[xsl] generate-id() and setting an ID attribute uniquely in the XML output for the same source node output twice.

Subject: [xsl] generate-id() and setting an ID attribute uniquely in the XML output for the same source node output twice.
From: David Holden <dh@xxxxxxxx>
Date: Tue, 18 Nov 2003 15:55:51 +0000

Hi,

 I have a source document something like this:

<doc>
      <textlevel id="textlevel1">

       <!-- 
     text marked up using xml tags, e.g. i for italic, b for bold, formula for       
math etc.. one of which is a "span" tag, e.g.
       -->

      <i>text text text</i> <span id="s1">text text text</span> text text 
<b>text</b>

   </textlevel>

  <!-- etc.... -->

</doc>


I need to transform this document and all of its text level markup to XML 
conforming to a different DTD, so I have template rules for all the source 
elements mapping to the target elements.


However I also need to make a structural change such that the textlevel 
element with id="textlevel1" and all of its contents after transformation are 
output in two different places in the resulting XML.


for example the result document may look like.

<resultdoc>
    <newstructure_e1>
   
        <textlevel>

                   <!-- source elements transformed to new DTD source element, 
one of which is a span element -->

      <newi>text text text</newi> <newspan id="s1">text text text</newspan> 
text text <newb>text</newb>

        </textlevel>
    </newstructure_e1>
    <newstructure_e2>

        <textlevel>

                   <!-- source elements transformed to new DTD source element 
one of which is a span element -->

      <newi>text text text</newi> <newspan id="s2">text text text</newspan> 
text text <newb>text</newb>


       </textlevel>
    </newstructure_e2>
</resultdoc>


so the xsl may be 

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

<resultdoc>
   <newstructure_e1>
       <xsl:template apply-templates="/doc/textlevel[@id="id1"]>
   </newstructure_e1>
   <newstructure_e2>
       <xsl:template apply-templates="/doc/textlevel[@id="id1"]>
   </newstructure_e2>
</resultdoc>

<xsl:template match="/doc/textlevel">
    <textlevel>
        <xsl:template apply-templates/>
    </textlevel>
</xsl:template>

<xsl:template match="//span">
   <xsl:attribute name="id">
       <xsl:value-of select="./@id"/>
   </xsl:attribute>
</xsl:template>
      
<!-- other element mappings -->




The problem I have is how do I give the second output of the span element a 
unique ID, I don't care what the ID of the span elements are in the output 
document so long as they are unique.

I can't use generate-id() in the //span template since this bases it value on 
the position in the source document which is the same for both.



I've though about using "modes", e.g., in the first callout

 <xsl:template apply-templates="/doc/textlevel[@id="id1"]>

and in the second callout

 <xsl:template apply-templates="/doc/textlevel[@id="id1"] mode="differentid">

but then I have to provide two templates for all the other textlevel elements 
one with a mode and one with out (the actual document is more complicated 
than this.)

  Any ideas,

 thanks,

 Dave.


-- 
Dr. David Holden. (Systems Developer)
Crystallography Journals Online: <http://journals.iucr.org>

Thanks in advance:-
Please avoid sending me Word or PowerPoint attachments.
See: <http://www.fsf.org/philosophy/no-word-attachments.html>

UK Privacy (R.I.P)  : http://www.stand.org.uk/commentary.php3
Public GPG key available on request.
-------------------------------------------------------------

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread