[xsl] Inserting the value of a variable in a result-document

Subject: [xsl] Inserting the value of a variable in a result-document
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Mon, 30 Apr 2007 15:26:11 -0700
Hi List,

Thanks in advance for the help. Not sure why I'm having such a tough
time with this one, but here it goes. I'm using Saxon and XSLT 2.0.

Basically  I have a named template I'm calling that inserts a node
into a  bunch of small xml documents. Hoewever I'm not sure how to do
this as the param comming in is out of scope if I was to
apply-templates:

so if I started with:

file:///c:/test.xml
<root>
<foo>
  <bar>of the foo variety</bar>
  <insert>insert the text after this</insert>
 <foo>
   <bar>A deeper bar who is foo</bar>
 </foo>
</foo>
</root>

and wanted

file:///c:/test_new.xml
<root>
<foo>
  <bar>of the foo variety</bar>
  <insert>insert the text after this</insert>
  the new insert
 <foo>
   <bar>A deeper bar who is foo</bar>
 </foo>
</foo>
</root>

and had the template:


<xsl:template name="insert_node"> <xsl:param name="myNode"/> <xsl:param name="myInputDoc"/> <xsl:param name="myResultsFile"/> <xsl:variable name="inDoc" select="document($myInputDoc)"/>

 <xsl:result-document href="{$myResultsFile}">
  <!-- Here I'm not sure what to do with $inDoc, apply-templates with
a mode makes me lose $myNode and a for-each doesn't keep my original
structure -->
  </xsl:result-document>
</xsl:template>


an called my template with



<xsl:call-template name="insert_node"> <xsl:with-param name="myNode">the new insert</xsl:with-param> <xsl:with-param name="myInputDoc">file:///c:/test.xml</xsl:with-param> <xsl:with-param name="myResultsFile">file:///c:/test_new.xml</xsl:with-param> </xsl:call-template>


What would be the best way to do this.


Thanks,

Spencer

Current Thread