开发者

xslt 1.0 preceding-sibling for sorted group

I need to run a conditional action based on the preceding sibling in a sorted group. I know that the preceding-sibling function acts on the original document, not the sorted results. Is there a way开发者_运维知识库 to operate on the sorted results list? I do not think the muenchian grouping method is what I need because I do not want to group based on the preceding-sibling.

Given the xml below I want to sort by the value of the container, and then test to see if the type attribute of the preceding-sibling (within the sorted results) is different, if it is I need to output the value of the new @type, but I do not want the results sorted by @type.

XML

<c>
     <did>
        <container id="cid1059023" type="Box">C 3</container>
        <container id="cid1059004" type="Map-case">C 1</container>
        <container id="cid1059002" type="Binder">OSxxx-3</container>
        <container id="cid1059042" type="Box">OSxxx-1</container>
     </did>
 </c>
<c>
     <did>
        <container id="cid1059025" type="Box">C 4</container>
        <container id="cid1059006" type="Map-case">C 2</container>
     </did>
 </c>

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="1.0">
    <xsl:template match="/">
        <table>
            <xsl:for-each select="child::*/container[@id]">
                <xsl:sort select="."/>
                <tr>
                   <td class="container">
                       <xsl:if test="@type != preceding-sibling::*/@type">
                           <xsl:value-of select="@type"/>
                       </xsl:if>
                       <xsl:value-of select="."/>
                    </td>
                </tr>
            </xsl:for-each> 
        </table>
    </xsl:template>
</xsl:stylesheet>

Thanks.


I don't see how you can do this with XSLT 1.0 without using extension. So I would either use XSLT 2.0, or, if you have someone with a gun pointed at you yelling you shall use XSLT 1.0, then you could create a pipeline with two XSLT steps, do the sorting in a first step, and the filtering in a second.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜