xsl-list
[Top] [All Lists]

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

2011-12-31 04:59:59
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>