Subject: Re: [xsl] generate-id accross different xsl files From: Francis Norton <francis@xxxxxxxxxxx> Date: Sat, 05 May 2001 16:33:43 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] generate-id accross diffe, Jeni Tennison | Thread | RE: [xsl] generate-id accross diffe, Chris Bayes |
Re: [xsl] Doing multiple tranformat, Johannes Döbler | Date | RE: [xsl] generate-id accross diffe, Chris Bayes |
Month |