You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Sticker, Markus / Kuehne + Nagel / Ham MI-EC /external" <ex...@Kuehne-Nagel.com> on 2010/10/06 15:40:33 UTC
XSLT-Problem: How to copy nodes from template to variable and calling this variable to getting nodes
Hello,
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.
Thanks for your help
best regards
Markus
XSLT-File
----------
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://somewhere.com/v_1_6/outgen" xmlns:kn="knExt" xmlns:saxon="http://saxon.sf.net/" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xalan="http://xml.apache.org/xalan" extension-element-prefixes="kn saxon" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="xalan a exslt fn saxon">
<xsl:output method="xml"/>
<xsl:template match="/">
<!-- this works fine - start -->
<xsl:variable name="def" as="node()*">
<bo>
<item>1</item>
<boline>4</boline>
<totals>6</totals>
</bo>
</xsl:variable>
<xsl:value-of select="{exslt:node-set($def)/bo/item}"/>
<!-- this works fine - end -->
<!-- this is the part - start -->
<xsl:variable name="headlines" as="node()*">
<xsl:call-template name="headlines"/>
</xsl:variable>
<xsl:value-of select="exslt:node-set($headlines)" />
</xsl:template>
<xsl:template name="headlines" as="item()*">
<field name="L_head">
<xsl:value-of select="a:doc/a:Headlines"/>
</field>
</xsl:template>
<!-- this is the part - end -->
</xsl:stylesheet>
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>
Kuehne + Nagel (AG & Co.) KG, Geschaeftsleitung: Hans-Georg Brinkmann (Vors.), Dirk Blesius, Reiner Heiken, Bruno Mang, Alfred Manke, Christian Marnetté, Mark Reinhardt, Jens Wollesen, Klaus Jaeger (stellv.), Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Persoenlich haftende Gesellschaft: Kuehne & Nagel A.G., Sitz: Contern/Luxemburg Geschaeftsfuehrender Verwaltungsrat: Klaus-Michael Kuehne
Re: XSLT-Problem: How to copy nodes from template to variable and
calling this variable to getting nodes
Posted by Michael Ludwig <mi...@gmx.de>.
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