|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Identifier attribute (was: Re: Creating Hie
Rowan,
Run as a second pass, a near-identity transform could append any input with identifiers, constructed however you like. Run on the result of an earlier transformation, the logic it would use to construct its identifiers would of course refer to that result, rather than to an earlier input. This makes it simpler and potentially much more robust. So: <xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="." mode="mark-id"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template><xsl:template match="a | b | c | d" mode="mark-id">
<!-- match any elements you want to mark with an id -->
<xsl:attribute name="id">
<xsl:number count="a | b | c | d" level="any"/>
</xsl:attribute>
</xsl:template><xsl:template match="*" mode="mark-id"/> <!-- matching other elements in the 'mark-id' mode does nothing --> Note that this may place an attribute named 'id' on elements that already have one, in which case the old value will be overwritten. Apart from that wrinkle, however, this is probably the most general way to approach the problem. If you don't want to run your id-marking process as a second pass, it can be done in the main stylesheet too. But since there, the transformation must refer to the original source rather than its own result, constructing the identifiers (and being sure they are unique) can be complex. How complex depends on how complex the transformation is and the specific requirements for the id attributes (where they have to be, etc.). Remember also that XSLT 2.0 can pipeline natively, so two passes can be achieved using one stylesheet. I hope that helps, Wendell At 09:04 AM 10/20/2008, you wrote: Thanks for all your comments. The XML file I need to create was designed by someone else and is interpreted by code which don't have access to. It has attributes with the name "id" and increasing integer values, so this is what I have to generate. I guess these don't use the id semantics. Using <xsl:number/> as suggested by Ken works fine in this particular case, and is very much easier than what I was trying to find a way of doing, which was rather than using the sequence number of the nodes in the input file, to work out how many nodes had been generated in the output file. ====================================================================== 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 ======================================================================
|
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








