Re: [xsl] Is it possible to access a tag after using apply-templates?

Subject: Re: [xsl] Is it possible to access a tag after using apply-templates?
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Fri, 04 Jul 2008 16:45:31 +0200
XemonerdX schrieb:
Unfortunately that's not quite the result. I can't seem to be able to
replace the 'insert-cell-name' and 'insert-cell-value' tags with the
corresponding 'name' and 'value' tag values. Is this possible?

Hi Edwin,

in addition to what Martin has already supplied, you may want to try the
following XSL 1.0 solution, which produces the desired output. Note the
identity template with parameter at the end tries to emulate tunnel

<xsl:transform version="1.0"
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:param name="data-file" select="'XemonerdX-2008-07-04.xml'"/>
  <xsl:variable name="root" select="/"/>
  <xsl:variable name="data-doc" select="document( $data-file )"/>

  <xsl:template match="layout | layout-main"><!-- pass through -->
    <xsl:apply-templates select="*"/>
  <xsl:template match="layout-cell"/><!-- do not go down here -->

  <xsl:template match="title">
    <xsl:copy-of select="$data-doc/top/data/title"/>

  <xsl:template match="insert-name">
    <xsl:value-of select="$data-doc/top/data/name"/>

  <xsl:template match="insert-cells">
    <xsl:for-each select="$data-doc/top/cells/cell">
      <xsl:variable name="current-cell" select="."/>
      <xsl:apply-templates select="$root/layout/layout-cell/*" mode="cell">
        <xsl:with-param name="current-cell" select="$current-cell"/>

  <xsl:template match="insert-cell-name">
    <xsl:apply-templates select="/layout/layout-cell/*"/>

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

  <!-- identity template with parameter -->
  <xsl:template match="@*|node()" mode="cell">
    <xsl:param name="current-cell"/>
      <xsl:apply-templates select="@*|node()" mode="cell">
        <xsl:with-param name="current-cell" select="$current-cell"/>
  <!-- placeholder to be filled in -->
  <xsl:template match="insert-cell-name" mode="cell">
    <xsl:param name="current-cell"/>
    <xsl:value-of select="$current-cell/name"/>
  <!-- another placeholder -->
  <xsl:template match="insert-cell-value" mode="cell">
    <xsl:param name="current-cell"/>
    <xsl:value-of select="$current-cell/value"/>

Michael Ludwig

Current Thread