[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: generate-id accross different xsl files

Subject: Re: generate-id accross different xsl files
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Sat, 05 May 2001 16:33:43 +0100
norton generate
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

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.