0

Trying to transform this simple xml using two passes:

<root>
  <a>Init</a>
</root>

The answer from 2011 (for the same question) does not seem to work. Please see: Doing a double-pass in XSL?). Template (same as in the original post) is:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:variable name="firstPassResult">
    <xsl:apply-templates select="/" mode="firstPass"/>
  </xsl:variable>

  <xsl:template match="/" mode="firstPass">
      <test>
        <firstPass>
          <xsl:value-of select="root/a"/>
        </firstPass>
      </test>
  </xsl:template>

  <xsl:template match="/">
    <xsl:apply-templates select="$firstPassResult" mode="secondPass"/>
  </xsl:template>

  <xsl:template match="/" mode="secondPass">
    <xsl:message terminate="no">
      <xsl:copy-of select="."/>
    </xsl:message>
  </xsl:template>

</xsl:stylesheet>

I am using XSLT 2.0. Any thoughts/feedback welcome... please.

Community
  • 1
  • 1
L C
  • 5
  • 2

1 Answers1

0

Your last template:

<xsl:template match="/" mode="secondPass">
  <xsl:message terminate="no">
    <xsl:copy-of select="."/>
  </xsl:message>
</xsl:template>

directs the entire output to a message - which your implementation may or may not show. If you want to see the result in the output tree, change it to:

<xsl:template match="/" mode="secondPass">
    <xsl:copy-of select="."/>
</xsl:template>

P.S. I am not sure this is the best example of two-pass processing. Why don't you ask your own question, describing your own situation.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Yes, thank you ! I had a more complicated issue with CDATA ... and had to apply multiple passes. This helped, thanks Michael ! I will look into how a message works, too. – L C Oct 26 '15 at 20:39