problem passing a value using with-param
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 17
- Joined: Tue Feb 05, 2008 11:14 pm
problem passing a value using with-param
New to XSLT and here's an example of what I'm trying to do. My problem is that the value of foo is not getting passed from parsefoo to parser. I've tried some other ways, but nothing seems to work...any ideas? Like I said, I'm new to XSLT so if you see any other problems with the sample feel free to point them out. Thanks in advance.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="nodes" select="/root/node"/>
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"></xsl:call-template>
</xsl:variable>
</xsl:template>
<xsl:template name="parsefoo">
<xsl:for-each select="$nodes">
<xsl:call-template name="parser">
<xsl:with-param name="val"><xsl:value-of select="foo"/></xsl:with-param>
<xsl:with-param name="delimiter">" "</xsl:with-param>
<xsl:with-param name="elementName">"item"</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="parser">
<xsl:param name="val"/>
<xsl:param name="delimiter"/>
<xsl:param name="elementName"/>
<xsl:for-each select="tokenize($val,$delimiter)">
<xsl:element name="{$elementName}">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: problem passing a value using with-param
Post by sorin_ristache »
Hello,
The template parsefoo is not called because the variable foos is not used. If you declare a variable but you do not use it the XSLT processor may not evaluate the variable. Saxon 9 works in this way on your XSLT 2.0 stylesheet. For example if you replace the first template with
the value of element foo is passed correctly.
Regards,
Sorin
The template parsefoo is not called because the variable foos is not used. If you declare a variable but you do not use it the XSLT processor may not evaluate the variable. Saxon 9 works in this way on your XSLT 2.0 stylesheet. For example if you replace the first template with
Code: Select all
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<xsl:value-of select="$foos"/>
</xsl:template>
Regards,
Sorin
-
- Posts: 17
- Joined: Tue Feb 05, 2008 11:14 pm
Re: problem passing a value using with-param
That doesn't appear to have any effect I ran it through the XSLT debugger in Oxygen, using Saxon 9B, and still no value in 'val'. I must be doing something else wrong. Let me know if you see anything else. Here's the updated code.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="nodes" select="/root/node"/>
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
</xsl:template>
<xsl:template name="parsefoo">
<xsl:for-each select="$nodes">
<xsl:call-template name="parser">
<xsl:with-param name="val"><xsl:value-of select="foo"/></xsl:with-param>
<xsl:with-param name="delimiter">" "</xsl:with-param>
<xsl:with-param name="elementName">"item"</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="parser">
<xsl:param name="val"/>
<xsl:param name="delimiter"/>
<xsl:param name="elementName"/>
<xsl:for-each select="tokenize($val,$delimiter)">
<xsl:element name="{$elementName}">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: problem passing a value using with-param
Post by sorin_ristache »
I see that you did not change the XSLT stylesheet as I specified in the previous post. Please add a reference to the foos variable for evaluating it. For example replace
with
Regards,
Sorin
Code: Select all
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
</xsl:template>
Code: Select all
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<xsl:value-of select="$foos"/>
</xsl:template>
Sorin
-
- Posts: 17
- Joined: Tue Feb 05, 2008 11:14 pm
Re: problem passing a value using with-param
I forgot to include that in my post, but it doesn't seem to have any affect.
Here's some sample XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="nodes" select="/root/node"/>
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<xsl:value-of select="$foos"/>
</xsl:template>
<xsl:template name="parsefoo">
<xsl:for-each select="$nodes">
<xsl:call-template name="parser">
<xsl:with-param name="val"><xsl:value-of select="foo"/></xsl:with-param>
<xsl:with-param name="delimiter">" "</xsl:with-param>
<xsl:with-param name="elementName">"item"</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="parser">
<xsl:param name="val"/>
<xsl:param name="delimiter"/>
<xsl:param name="elementName"/>
<xsl:for-each select="tokenize($val,$delimiter)">
<xsl:element name="{$elementName}">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<root>
<node>
<foo>test1</foo>
</node>
<node>
<foo>test2</foo>
</node>
<node>
<foo>test3</foo>
</node>
</root>
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: problem passing a value using with-param
Post by sorin_ristache »
The name of a tag cannot contain the character ". You have to replace
with
For sending in the output the complete content of the foos variable including the markup you should replace
with
With this template I get the following output from your 2 input files:
Regards,
Sorin
Code: Select all
<xsl:with-param name="elementName">"item"</xsl:with-param>
Code: Select all
<xsl:with-param name="elementName">item</xsl:with-param>
Code: Select all
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<xsl:value-of select="$foos"/>
</xsl:template>
Code: Select all
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<output>
<xsl:copy-of select="$foos"/>
</output>
</xsl:template>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<output>
<item>test1</item>
<item>test2</item>
<item>test3</item>
</output>
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: problem passing a value using with-param
Post by sorin_ristache »
I get the following output both in the Editor perspective and in the XSLT Debugger perspective
with Saxon 9B applied to the following XML file and XSLT file:
Regards,
Sorin
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<output>
<item>test1</item>
<item>test2</item>
<item>test3</item>
</output>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<node>
<foo>test1</foo>
</node>
<node>
<foo>test2</foo>
</node>
<node>
<foo>test3</foo>
</node>
</root>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="nodes" select="/root/node"/>
<xsl:template match="/">
<xsl:variable name="foos">
<xsl:call-template name="parsefoo"/>
</xsl:variable>
<output>
<xsl:copy-of select="$foos"/>
</output>
</xsl:template>
<xsl:template name="parsefoo">
<xsl:for-each select="$nodes">
<xsl:call-template name="parser">
<xsl:with-param name="val"><xsl:value-of select="foo"/></xsl:with-param>
<xsl:with-param name="delimiter">" "</xsl:with-param>
<xsl:with-param name="elementName">item</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="parser">
<xsl:param name="val"/>
<xsl:param name="delimiter"/>
<xsl:param name="elementName"/>
<xsl:for-each select="tokenize($val,$delimiter)">
<xsl:element name="{$elementName}">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service