|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:number and including nodes with xsl:key
Michael, your pointer to that earlier discussion did the trick. Thanks
to you and Bill for the responses.
Just for posterity's sake, here's what I did: === Input xml: === <test> <extra myid="extraid"><name>Extra item</name></extra> <item> <name>Item one</name> <name>Item two</name> <name>Item three</name> <insert ref="extraid"/> </item> </test> === XSL === <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" > <xsl:key name="testkey" match="extra" use="@myid"/> <!-- process the source tree to do inclusions, then process that result tree as a new source tree --> <xsl:template match="/"> <xsl:variable name="transcluded-doc"> <xsl:call-template name="do-transclusion"/> </xsl:variable> <xsl:apply-templates select="xalan:nodeset($transcluded-doc)" mode="normal"/> </xsl:template> <!-- templates for copy mode --> <!-- identity transform for copying source tree to interim result tree --> <xsl:template match="@*|node()" name="do-transclusion" mode="copy"> <xsl:copy> <xsl:apply-templates select="@*|node()" mode="copy"/> </xsl:copy> </xsl:template> <!-- don't output 'extra' nodes to the interim tree; they'll get included
by 'insert' nodes -->
<xsl:template match="extra" mode="copy"/><!-- for 'insert' nodes, insert the content of the specified 'extra' node
instead. -->
<xsl:template match="insert" mode="copy">
<xsl:variable name="d" select="key('testkey',@ref)"/>
<xsl:for-each select="$d/name">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:template><!-- end copy templates --> <!-- begin output templates --> <!-- identity transform, for testing --> <xsl:template match="@*|node()" mode="normal"> <xsl:copy> <xsl:apply-templates select="@*|node()" mode="normal"/> </xsl:copy> </xsl:template> <!-- number the name nodes so we can see that numbering now works as we need
it to. -->
<xsl:template match="name" mode="normal">
<xsl:number/> - <xsl:value-of select="."/>
</xsl:template></xsl:stylesheet> === output === <?xml version="1.0" encoding="UTF-8"?> <test> <item> 1 - Item one 2 - Item two 3 - Item three 4 - Extra item </item> </test> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








