This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Need help with apply-templates to set variables
- From: Brad Cox <bcox at virtualschool dot edu>
- To: xsl-list at lists dot mulberrytech dot com
- Cc: Brad Cox <bcox at virtualschool dot edu>, <www-xpath-comments at w3 dot org>
- Date: Sun, 3 Feb 2002 13:35:50 -0500
- Subject: [xsl] Need help with apply-templates to set variables
- Reply-to: xsl-list at lists dot mulberrytech dot com
This is driving me crazy. I've been hung on this problem all
day. Could someone please help? I'm trying to use a xalan
extension to call one of my java functions. The extension logic
is working and the function is being called ok. The problem is
that it only gets the text content of each node. All xhtml
markup is being removed.
Here's the nub the problem. See below for the full stylesheet.
<xsl:template match="page">
<xsl:variable name="body">
#parse("vel/macros.vel")
#taskOpening("@ident")
<xsl:apply-templates select="*"/>
#taskClosing("@ident")
</xsl:variable>
PageText{<xsl:value-of select="$body"/>}
<xsl:value-of select="task:addPage($task, @ident, $body)" />
</xsl:template>
When $body is received (as a String) by my addPage routine, it
contains only text with all markup removed. For example, for
this input
<task ident="HelloWorld">
<page ident="LoremIpsem">
<p>Foo</p>
</page>
</task>
I see CopyOf{Foo} in the output when I want to be seeing
<p>CopyOf(<p>Foo</p>)</p>.
It seems that markup is deleted only when the results are saved
in a variable. If I add a <xsl:apply-templates select="*"/>
outside of the variable assignment in the above, the output
contains markup as expected.
Here is the whole stylesheet.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:task="edu.virtualschool.model.Task"
extension-element-prefixes="task"
exclude-result-prefixes="java"
>
<xsl:output method="html"/>
<xsl:param name="task">null</xsl:param>
<xsl:template match="/task">
#set($totalPages = <xsl:value-of select="count(page)"/>)
#set($pageTitles = [<xsl:for-each select="page">"<xsl:value-of
select="@ident"/>",</xsl:for-each>"Submit page"])
<xsl:apply-templates select="page"/>
</xsl:template>
<xsl:template match="page">
<xsl:variable name="body">
#parse("vel/macros.vel")
#taskOpening("@ident")
<xsl:apply-templates select="*"/>
#taskClosing("@ident")
</xsl:variable>
PageText{<xsl:value-of select="$body"/>}
<xsl:value-of select="task:addPage($task, @ident, $body)" />
</xsl:template>
<xsl:template
match="EmailQuestion|EssayQuestion|NameQuestion|UrlQuestion|PhoneQuestion"
>
#<xsl:value-of select="name()"/>("<xsl:value-of
select="@ident"/>" "<xsl:value-of select="normalize-
space(text())"/>")
</xsl:template>
<xsl:template match="MenuQuestion|RadioQuestion|CheckboxQuestion">
#<xsl:value-of select="name()"/>("<xsl:value-of
select="@ident"/>" "<xsl:value-of select="normalize-
space(text())"/>" [<xsl:for-each select="option">"<xsl:value-of
select="."/>"<xsl:if test="not(position() =
last())">,</xsl:if></xsl:for-each>])
</xsl:template>
<xsl:template match="*">
<p>CopyOf{<xsl:copy-of select="."/>}</p>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list