[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

Subject: Re: xsl:number and including nodes with xsl:key
From: Denis Haskin <Denis@xxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Aug 2003 10:07:06 -0400
haskin
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.