Re: [xsl] Path according to a child node attribute

Subject: Re: [xsl] Path according to a child node attribute
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 31 Dec 2011 11:59:51 +0100
Gian Paolo Bernardini wrote:

I'm founding difficulties on adding a child element as last child of the
node (i.e.<Path>) and on making the right path building (i.e. accessing the
attributes and values of the father, of the grandfather or of the great
grandfather based on the SuperClass code of each Class).
Using SaxonHE9-4-0-1J.

Any ideas? Thanks in advance

Here is a sample stylesheet:


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

<xsl:key name="k1" match="Class" use="@code"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="Class">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<Path>
<xsl:apply-templates select="key('k1', SuperClass/@code)" mode="path"/>
</Path>
</xsl:copy>
</xsl:template>


  <xsl:template match="Class" mode="path">
    <xsl:variable name="next" select="key('k1', SuperClass/@code)"/>
    <xsl:if test="$next">
      <xsl:apply-templates select="$next" mode="path"/>
      <xsl:text>/</xsl:text>
    </xsl:if>
    <xsl:value-of select="concat(@code, ' ', Rubric)"/>
  </xsl:template>

</xsl:stylesheet>



--

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

Current Thread