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

Re: Problem with generating references.

Subject: Re: Problem with generating references.
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 5 Jul 2005 13:56:56 +0100
references id
When gereating references it's usually easiest to make sure that current
node is the same (referenced) node, both at the point where you make the
reference, and at the point where you make the anchor, That way it is
easy to make sure that you generate the same ID, eitherusing numbering
or, as here, using generate-id.

something like



<A1>
         <B1/>
         <B2>
                  <C1></C1>
                  <C2>
                           <D1/>
                  </C2>
         </B2>
</A1>





<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">



<xsl:output indent="yes"/>

<xsl:key name="d" match="*" use="count(ancestor::*)"/>

<xsl:template match="/">
<xsl:for-each select="//*[generate-id()=generate-id(key('d',count(ancestor::*)))]">
<xsl:variable name="d" select="count(ancestor::*)"/>
<xsl:variable name="n">
 <xsl:number value="$d+1" format="A"/>
</xsl:variable>
<xsl:element name="{$n}-Group">
 <xsl:for-each select="key('d',$d)">
  <xsl:copy>
   <xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>
  <xsl:for-each select="*">
  <reference id="{generate-id()}"/>
  </xsl:for-each>
   </xsl:copy>
 </xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


$ saxon ids.xml ids.xsl
<?xml version="1.0" encoding="utf-8"?>
<A-Group>
   <A1 id="d0e1">
      <reference id="d0e3"/>
      <reference id="d0e5"/>
   </A1>
</A-Group>
<B-Group>
   <B1 id="d0e3"/>
   <B2 id="d0e5">
      <reference id="d0e7"/>
      <reference id="d0e9"/>
   </B2>
</B-Group>
<C-Group>
   <C1 id="d0e7"/>
   <C2 id="d0e9">
      <reference id="d0e11"/>
   </C2>
</C-Group>
<D-Group>
   <D1 id="d0e11"/>
</D-Group>



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.