Re: XSLT-Problem: How to copy nodes from template to variable and calling this variable to getting nodes

Michael Ludwig <[email protected]> Wed, 6 Oct 2010 23:23:26 +0200
Newsgroups gmane.text.xml.xalan.java.user
Message-ID <20101006212326.GI3984@wladimir>
Moin Markus!

Sticker, Markus / Kuehne + Nagel / Ham MI-EC /external schrieb am
06.10.2010 um 15:40 (+0200):
> 
> I have a problem to fill a variable with nodes from a template.
> After that I want to call this variable to place this nodes.
> But what I get is a long String.

That's probably because you do not yet know that you want xsl:copy-of
instead of xsl:value-of.

> <xsl:stylesheet version="2.0"

Be aware that Xalan is XSLT 1.0; for 2.0, you need Saxon, Altova,
XQSharp, or, IIRC, some Intel or IBM enterprise package.

> 	<xsl:output method="xml"/>
> 	<xsl:template match="/">
> 
> <!-- this works fine  -  start -->
> 		<xsl:variable name="def" as="node()*">

Note that *as="..."* is a 2.0 feature.

> 			<bo>
> 				<item>1</item>
> 				<boline>4</boline>
> 				<totals>6</totals>
> 			</bo>
> 		</xsl:variable>
> 
> <xsl:value-of select="{exslt:node-set($def)/bo/item}"/>

And with 2.0, you wouldn't need the node-set extension, because in 2.0
the RTF (result tree fragment) has been abolished, and your variable
would be a full-fledged node set.

> <!-- this works fine  -  end -->
> 
> <!-- this is the part -  start -->

Drop the part I snipped.

> XML-file
> -----------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <doc xmlns="http://somewhere.com/v_1_6/outgen">
>     <Headlines id="23467201">Dog bites man</Headlines>
>     <Headlines id="23423441">Man bites dog</Headlines>
> </doc>

Try this:

  xsl:copy-of select="/a:doc/a:Headlines"/>

Or this, if the doc is not your primary input:

  <xsl:copy-of select="document( $doc-uri )/*/*"/>

-- 
Michael Ludwig