2

I have to use XSL 1.0 and I have an xslt variable containing a result tree fragment. I want to apply template styles to that variable.

 <xsl:template match="item">
   <p>
     <xsl:apply-templates />
   </p>     
 </xsl:template>

 <xsl:template match="html_embed">
   <xsl:variable name="htmlContents">
     <item>hello ian</item>
     <item>how are you?</item>
   </xsl:variable>

   <xsl:choose>
     <xsl:when test="function-available('msxsl:node-set')">
       <xsl:apply-templates select="msxsl:node-set($htmlContents)/node()" /> 
     </xsl:when>
     <xsl:otherwise>
       <p>node set not available</p>
     </xsl:otherwise>
   </xsl:choose>

 </xsl:template>

I'm using the node-set function to turn the tree fragment into a node-set but it either isn't working or it can't find a template match because all that's ever returned is this text, on one line, without the markup:

hello ianhow are you?

Any idea's on how I can transform the item nodes?

Robini
  • 377
  • 1
  • 3
  • 14
  • I tried and it works for me. I changed the `html_embed` to `/` to be able to apply your template on any xml document and this is what I got: `

    hello ian

    how are you?

    `. Note that I used Visual Studio to run this transformation (so the processor was XslCompiledTransform). I vaguely remember that the native xslt processor behaved a bit differently. I would try `msxsl:node-set($htmlContents)//*` and then `msxsl:node-set($htmlContents)/*/*` and then try replacing the last `*` with `item`
    – Pawel Oct 25 '12 at 23:23
  • 2
    Please, edit the question and provide the complete source XML document (as small as needed to repro the problem) and the complete XSLT stylesheet (as small as needed to repro the problem). With the current information one can only *guess*. My guess is that you have in the code that you ahaven't shown to us the following: `` . If this is the case, just remove this XSLT instruction and, if there are no other problems, you may get the wanted result. – Dimitre Novatchev Oct 26 '12 at 01:38

0 Answers0