S
shaun roe
I have a document about 4 levels deep and in my XSLT I want to generate
a unique string ID for each basic element based on its path through the
hierarchy.
If I use recursion, I am continually accessing the root element ID, here
is a typical call:
<xsl:variable name="fullPath"
select="concat('p',../../../@id,'_c',../../@id,'_r',../@id,'_s',$slaveID)
"/>
I *could* do this by nesting call-templates and passing the current id
as a parameter. Is this likely to be more or less efficient?
e.g. starting xml:
<castle id="0>
<level id="2">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
<level id="3">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
</castle>
so heres an xslt:
<xsl:template match="castle">
<xsl:fullPath select="concat('c',@id)"/>
<thisCastle uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="level">
<xsl:fullPath select="concat('c',../@id,'_l',@id)"/>
<thisLevel uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="room">
<xsl:fullPath select="concat('c',../../@id,'_l',../@id,'_r',@id)"/>
<thisRoom uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
I'm guessing this is very inefficient, accessing the castle ID for each
room. is there a better way? I could generate an ID, but would the ID
reflect the data path it took to get to a particular room?
cheers
shaun
a unique string ID for each basic element based on its path through the
hierarchy.
If I use recursion, I am continually accessing the root element ID, here
is a typical call:
<xsl:variable name="fullPath"
select="concat('p',../../../@id,'_c',../../@id,'_r',../@id,'_s',$slaveID)
"/>
I *could* do this by nesting call-templates and passing the current id
as a parameter. Is this likely to be more or less efficient?
e.g. starting xml:
<castle id="0>
<level id="2">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
<level id="3">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
</castle>
so heres an xslt:
<xsl:template match="castle">
<xsl:fullPath select="concat('c',@id)"/>
<thisCastle uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="level">
<xsl:fullPath select="concat('c',../@id,'_l',@id)"/>
<thisLevel uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="room">
<xsl:fullPath select="concat('c',../../@id,'_l',../@id,'_r',@id)"/>
<thisRoom uid="{$fullPath}"/>
<xsl:apply-templates/>
</xsl:template>
I'm guessing this is very inefficient, accessing the castle ID for each
room. is there a better way? I could generate an ID, but would the ID
reflect the data path it took to get to a particular room?
cheers
shaun