[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Creating custom IDs using Parent name tree


Subject: [xsl] Creating custom IDs using Parent name tree
From: "Wasiq Shaikh" <wasiq911@xxxxxxxxxxx>
Date: Tue, 24 Jul 2007 10:04:25 -0400

Hello again,

I'm trying to generate a custom ID attribute that uses the parent id, which contains a concatenation of its parent name. An example input file:

<root>
<element name="abc">
  <element name="def">
      <element name="ghi"/>
  </element>
</element>

<element name="xyz">
  <element name="def"/>
  <element name="ghi"/>
</element>
</root>

My xsl turns this structure into a flat list using a key and a variable:

<xsl:key name="allElements" match="xsd:element" use="concat(@name,' ',@type,' ',@ref)"/>

<!-- Defines a variable containing all unique elements -->
<xsl:variable name="allUniqueElements"
select="//xsd:element[@type and generate-id()=generate-id(key('allElements',concat(@name,' ',@type,' ',@ref)))]
| //xsd:element[not(string(@type))]"/>


(dont mind the small details) I then put these elements into a process

<xsl:template match="/">
<xsl:element name="Elements">
<xsl:for-each select="$allUniqueElements[not(@ref)]">
<xsl:sort select="@name"/>
<xsl:call-template name="processElement"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
... ...
<!-- Process top level elements -->
<xsl:template name="processElement">
<xsl:element name="element">
<xsl:if test="string(@name)">
<xsl:attribute name="id">
<!-- THIS IS WHERE I GET STUCK! -->
<xsl:value-of select="concat(PARENT_ID,'.',THIS_ELEMENTS_NAME)"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
</xsl:if>
...


The parent ID is also generated, and is not included in the input xml file. For example, the desired resulting document would be this

<Elements>
 <element id="abc" name="abc">
 <element id="abc.def" name="def">
 <element id="abc.def.ghi" name="ghi">
 <element id="xyz" name="xyz">
 <element id="xyz.def" name="def">
 <element id="xyz.ghi" name="ghi">
</Elements>

Which would mean that when processing element "ghi" the parent ID must be "abc.def" then concat '.' and 'ghi' to it. But how do i get that ID "abc.def" ?

So, since I'm processing elements that have no ID in the first place, how do I create the ID AND concatenate it with the current element's name?

Can this be done? Please point me in the right direction for this type of problem. All suggestions are appreciated. Thank you!


Wasiq Shaikh


_________________________________________________________________
Windows Live Hotmail is the next generation of MSN Hotmail. Its fast, simple, and safer than ever and best of all  its still free. Try it today! www.newhotmail.ca?icid=WLHMENCA146



Current Thread
Keywords