[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: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 29 Aug 2003 11:57:07 -0400
|
Denis,
This is cool, but could you explain again for the curious why
<xsl:number count="name|insert"/>
wouldn't work just as well?
Cheers,
Wendell
At 10:07 AM 8/29/2003, you wrote:
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>
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
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
RSS 2.0 |
|
Atom 0.3 |
|
|