[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: generate-id accross different xsl files
Jeni Tennison wrote: > > > If there's no way of generating something unique from the information > available around the node, then you can use the fact that it has a > unique position within the XML document to give you the ID. Two ones > that I might use are the following: > > - element name + count of previous elements with the same name > > <xsl:variable name="name" select="name()" /> > <xsl:value-of select="concat($name, '-', > count(preceding::*[name() = $name])" /> > But "the preceding axis contains all nodes in the same document as the context node that are before the context node in document order, <em>excluding any ancestors</em> and excluding attribute nodes and namespace nodes" (my <em/>) so ... --- C:\xml>type t.xml <?xml version="1.0" encoding="UTF-8"?> <a> <a> <a/> </a> </a> C:\xml>type t.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="*"> <xsl:copy> <xsl:attribute name="href"> <xsl:variable name="name" select="name()"/> <xsl:value-of select="concat($name, '-', count(preceding::*[name()= $name]))"/> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> C:\xml>saxon t.xml t.xslt <?xml version="1.0" encoding="UTF-8"?> <a href="a-0"> <a href="a-0"> <a href="a-0"/> </a> </a> --- But "NOTE: The ancestor, descendant, following, preceding and self axes partition a document (ignoring attribute and namespace nodes): they do not overlap and together they contain all the nodes in the document." So select="concat($name, '-', count(preceding::*[name()= $name]) + count(ancestor::*[name()= $name]))" should do it. Sometimes even noble Homer nods ... ;) Francis. 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
|