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 Guy McArthur <gu...@arizona.edu> on 2002/02/03 03:49:19 UTC

Re: xalan ignores xsl:output method="html"?

I'm not sure if this is a bug. <meta/> should come out as "<meta></meta>"  
in html, correct? At least that's my interpretation of the spec:

"The html output method should not output an end-tag for empty elements. 
For HTML 4.0, the empty elements are area, base, basefont, br, col, frame, 
hr, img, input, isindex, link, meta and param. For example, an element 
written as <br/> or <br></br> in the stylesheet should be output as <br>."
http://www.w3.org/TR/xslt#section-HTML-Output-Method

It looks like the default html output is now xhtml, e.g. I get the 
following namespace inserted into my html tag:

<html xmlns="http://www.w3.org/TR/xhtml1/transitional">

Guy



Re: xalan extensions, cont'd.

Posted by "Frank E. Weiss" <fr...@well.com>.
First, Brad, could you please fix your TO: and CC:. I'm on the xalan-j-users list, so I'm getting your emails twice.
Thanks.

Now, I want to make sure that you've read the XSL spec (forgive me if I sound stern, it's just very important to get
this)

7.6.1 Generating Text with xsl:value-of
"The required select attribute is an expression; this expression is evaluated and the resulting object is converted to a
string as if by a call to the string function"

It would also be good to carefully read:

11.3 Using Values of Variables and Parameters with xsl:copy-of

Therefore the template snippet

PageText{<xsl:value-of select="$body"/>}

will show no markup in the output. However, using xsl:copy-of will preserve the markup.

But I'm afraid your real problem arises when you call task:addPage($task, @ident, $body), where you're expecting that
$body is a string with markup. Read my earlier e-mail remarks on this problem.

Cheers -- Frank.

Brad Cox wrote:

> On Sunday, February 3, 2002, at 09:45 AM, Brad Cox wrote:
>
> > One last glitch and I"m there. All xhtml markup is being
> > stripped from $pageText.
>
> This is driving me crazy. I'm still hung on the same problem.
> Can someone please help? Here's the nub of it:
>
> <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>
>
> I've confirmed that the $body variable within the addPage
> routine contains only text minus markup. In particular, for
>
> <task ident="HelloWorld">
>         <page ident="LoremIpsem">
>                 <p>Foo</p>
>         </page>
> </task>
>
> I'm seeing CopyOf{Foo} in the output when I should be seeing
> <p>CopyOf(<p>Foo</p>)</p>. It appears that markup is deleted
> 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>


RE: xalan extensions, cont'd.

Posted by Gary L Peskin <ga...@firstech.com>.
Okay, Brad.  I understand the problem now.  Sorry, I'm a little slow on
this, trying to do 18 million things at once here.

You are passing $body into your extension function.  $body is a Result
Tree Fragment (RTF) as defined in the XSLT recommendation.  Since you
only have one method called addPage, the XalanJ extension mechanism
recognizes that it can map the RTF into a java String and successfully
call your extension method.  To map the RTF into a String, the XalanJ
extension mechanism effectively calls the XPath string() function.  This
basically returns the concatenation of all text node descendants of the
RTF, which is exactly what you're seeing.

The solution here is to specify the signature of your addPage method as:

  public void addPage(String ident, org.w3c.dom.traversal.NodeIterator
body)

Re: xalan extensions, cont'd.

Posted by Brad Cox <bc...@virtualschool.edu>.
On Sunday, February 3, 2002, at 01:51 PM, Gary L Peskin wrote:
> I'm afraid that I'm at a loss understanding exactly what the problem is
> from your description.  What leads you to believe that "markup is
> deleted when the results are saved in a variable"?  What does your
> addPage method look like now with this third argument?

Sorry I wasn't clear. Here's the addPage method:

	public void addPage( String ident, String body)
	{
		System.err.println("addPage:"+body);
		pages.add(new Page(this, ident, body, new 
IntegerField(pages.size())));
	}

With this xml input file:

<task ident="Lorem Ipsem">
<page ident="Intro">
<h2>Lorem Ipsem</h2>
<p>Lorem ipsum dolor sit amet</p>
</page>
</task>

The println statement should print

addPage:<h2>Lorem Ipsem</h2>
<p>Lorem ipsum dolor sit amet</p>

What I'm getting is:

addPage:Lorem Ipsem
Lorem ipsum dolor sit amet

If I add an apply-tempaltes outside the variable assignment, I 
see the correct output, e.g. with markup.

These omit the CopyOf{...} stuff (see below) which I added to 
help diagnose the problem.

>
>> -----Original Message-----
>> From: Brad Cox [mailto:bcox@virtualschool.edu]
>> Sent: Sunday, February 03, 2002 10:30 AM
>> To: Brad Cox
>> Cc: Gary L Peskin; xalan-j-users@xml.apache.org; 'Frank E. Weiss'
>> Subject: Re: xalan extensions, cont'd.
>>
>>
>> On Sunday, February 3, 2002, at 09:45 AM, Brad Cox wrote:
>>
>>> One last glitch and I"m there. All xhtml markup is being
>>> stripped from $pageText.
>>
>> This is driving me crazy. I'm still hung on the same problem.
>> Can someone please help? Here's the nub of it:
>>
>> <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>
>>
>> I've confirmed that the $body variable within the addPage
>> routine contains only text minus markup. In particular, for
>>
>> <task ident="HelloWorld">
>> 	<page ident="LoremIpsem">
>> 		<p>Foo</p>
>> 	</page>
>> </task>
>>
>> I'm seeing CopyOf{Foo} in the output when I should be seeing
>> <p>CopyOf(<p>Foo</p>)</p>. It appears that markup is deleted
>> 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|Ph
>> oneQuestion"
>>>
>> #<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>
>>
>
>
>
Brad Cox, Ph.D.; bcox@virtualschool.edu 703 361 4751
For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
Java Web Application Architecture: http://virtualschool.edu/jwaa


RE: xalan extensions, cont'd.

Posted by Gary L Peskin <ga...@firstech.com>.
Brad --

I'm afraid that I'm at a loss understanding exactly what the problem is
from your description.  What leads you to believe that "markup is
deleted when the results are saved in a variable"?  What does your
addPage method look like now with this third argument?

Gary

> -----Original Message-----
> From: Brad Cox [mailto:bcox@virtualschool.edu] 
> Sent: Sunday, February 03, 2002 10:30 AM
> To: Brad Cox
> Cc: Gary L Peskin; xalan-j-users@xml.apache.org; 'Frank E. Weiss'
> Subject: Re: xalan extensions, cont'd.
> 
> 
> On Sunday, February 3, 2002, at 09:45 AM, Brad Cox wrote:
> 
> > One last glitch and I"m there. All xhtml markup is being
> > stripped from $pageText.
> 
> This is driving me crazy. I'm still hung on the same problem. 
> Can someone please help? Here's the nub of it:
> 
> <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>
> 
> I've confirmed that the $body variable within the addPage 
> routine contains only text minus markup. In particular, for
> 
> <task ident="HelloWorld">
> 	<page ident="LoremIpsem">
> 		<p>Foo</p>
> 	</page>
> </task>
> 
> I'm seeing CopyOf{Foo} in the output when I should be seeing 
> <p>CopyOf(<p>Foo</p>)</p>. It appears that markup is deleted 
> 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|Ph
> oneQuestion"
>  >
> #<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>
> 


Re: xalan extensions, cont'd.

Posted by Brad Cox <bc...@virtualschool.edu>.
On Sunday, February 3, 2002, at 09:45 AM, Brad Cox wrote:

> One last glitch and I"m there. All xhtml markup is being 
> stripped from $pageText.

This is driving me crazy. I'm still hung on the same problem. 
Can someone please help? Here's the nub of it:

<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>

I've confirmed that the $body variable within the addPage 
routine contains only text minus markup. In particular, for

<task ident="HelloWorld">
	<page ident="LoremIpsem">
		<p>Foo</p>
	</page>
</task>

I'm seeing CopyOf{Foo} in the output when I should be seeing 
<p>CopyOf(<p>Foo</p>)</p>. It appears that markup is deleted 
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>


Re: xalan extensions, cont'd.

Posted by Brad Cox <bc...@virtualschool.edu>.
That's it!! Simple! Now I wonder why I didn't try that.

One last glitch and I"m there. This is working except that its 
stripping the xhtml markup from $pageText. How to make it 
serialize the <page>...</page> content, processed by 
apply-templates, to a String while retaining all xhtml markup?

<xsl:template match="page">
<xsl:variable name="pageText">
#parse("vel/macros.vel")
#taskOpening("@ident")
<xsl:apply-templates select="*"/>
#taskClosing("@ident")
</xsl:variable>
<xsl:value-of select="task:addPage($task, string(@ident), 
string($pageText))" />
</xsl:template>


On Sunday, February 3, 2002, at 02:09 AM, Gary L Peskin wrote:

> How about something like:
>
> <xsl:template match="page">
>
>   <xsl:variable name="someName">
>     <xsl:apply-templates/>
>   </xsl:variable>
>
>   <xsl:value-of select="task:addPage($task, string(@ident), 
> $someName)">
>
> </xsl:template>
>
> The type of $someName should be an XRTreeFrag, I believe.
>
> As far as the optional first argument, neither of those types is used
> for extension functions.  These are for extension elements.  You can
> specify an optional ExpressionContext as the first argument if you need
> any of its methods.
>
> HTH,
> Gary
>
>> -----Original Message-----
>> From: Brad Cox [mailto:bcox@virtualschool.edu]
>> Sent: Saturday, February 02, 2002 7:20 PM
>> To: xalan-j-users@xml.apache.org
>> Cc: Brad Cox; Frank E. Weiss
>> Subject: xalan extensions, cont'd.
>>
>>
>> More on the previously posted question. After considerable
>> tinkering, the code is actually running, invoking the
>> addPage(key, value) method on the task instance I passed as a
>> parameter as intended.
>>
>> The problem is that the value argument, as computed as
>> "string(.)", isn't what I want. I want the value to be the
>> result of <xsl:apply-templates/>, e.g. not the current node from
>> the input, but the node after being transformed by the other
>> templates in this file. I don't see how to do this. Can someone
>> please help?
>>
>> Here's the full xsl file I'm using:
>>
>> <?xml version="1.0"?>
>> <xsl:stylesheet version="1.0"
>> 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> 	xmlns:lxslt="http://xml.apache.org/xslt"
>> 	xmlns:java="http://xml.apache.org/xslt/java"
>> 	xmlns:task="edu.virtualschool.model.Task"
>> 	extension-element-prefixes="task"
>> 	exclude-result-prefixes="java"
>>>
>> <xsl:output method="html"/>
>> <xsl:param name="task"></xsl:param>
>>
>> <xsl:template match="/task">
>> #parse("vel/macros.vel")
>> #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:value-of select="task:addPage($task, string(@ident),
>> string(.))" /> </xsl:template>
>>
>> <xsl:template
>> match="EmailQuestion|EssayQuestion|NameQuestion|UrlQuestion">
>> #<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="*">
>> <xsl:copy-of select="."/>
>> </xsl:template>
>>
>> </xsl:stylesheet>
>>
>> For completeness, the code that launches the transform (from
>> Task.java)
>>
>> TransformerFactory tFactory =
>> TransformerFactory.newInstance(); Transformer transformer =
>> tFactory.newTransformer(new
>> StreamSource(xslFile.toString()));
>> transformer.setParameter( "task", this );
>> StringWriter sw = new StringWriter();
>> transformer.transform(
>> 	new StreamSource(xmlFile.toString()),
>> 	new StreamResult(sw)
>> );
>> System.err.println("out:"+sw); // printed and discarded
>> this.xmlModified = xmlFile.lastModified(); this.dvslModified
>> = dvslFile.lastModified();
>>
>> And the addPage method (from Task.java). I don't understand the
>> first two arguments; apparently they aren't needed/required/used
>> based on it working after commenting them
>> out.
>>
>> 	public void addPage(
>> 		//
>> org.apache.xalan.extensions.XSLProcessorContext context,
>> 		// org.apache.xalan.templates.ElemExtensionCall element,
>> 		String ident,
>> 		String body
>> 	)
>> 	{
>> 		String pageText =
>> 			"#parse(\"vel/macros.vel\")\n"+
>> 			"#taskOpening(\""+ident+"\")\n"+
>> 			body+"\n"+
>> 			"#taskClosing(\""+ident+"\")\n"+
>> 			"";
>> 		System.err.println("addPage:"+pageText);
>> 		pages.add(new Page(this, ident, pageText, new
>> IntegerField(pages.size())));
>> 	}
>>
>
>
>
Brad Cox, Ph.D.; bcox@virtualschool.edu 703 361 4751
For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
Java Web Application Architecture: http://virtualschool.edu/jwaa


RE: xalan extensions, cont'd.

Posted by Gary L Peskin <ga...@firstech.com>.
How about something like:

<xsl:template match="page">

  <xsl:variable name="someName">
    <xsl:apply-templates/>
  </xsl:variable>

  <xsl:value-of select="task:addPage($task, string(@ident), $someName)">

</xsl:template>

The type of $someName should be an XRTreeFrag, I believe.

As far as the optional first argument, neither of those types is used
for extension functions.  These are for extension elements.  You can
specify an optional ExpressionContext as the first argument if you need
any of its methods.

HTH,
Gary

> -----Original Message-----
> From: Brad Cox [mailto:bcox@virtualschool.edu] 
> Sent: Saturday, February 02, 2002 7:20 PM
> To: xalan-j-users@xml.apache.org
> Cc: Brad Cox; Frank E. Weiss
> Subject: xalan extensions, cont'd.
> 
> 
> More on the previously posted question. After considerable 
> tinkering, the code is actually running, invoking the 
> addPage(key, value) method on the task instance I passed as a 
> parameter as intended.
> 
> The problem is that the value argument, as computed as 
> "string(.)", isn't what I want. I want the value to be the 
> result of <xsl:apply-templates/>, e.g. not the current node from 
> the input, but the node after being transformed by the other 
> templates in this file. I don't see how to do this. Can someone 
> please help?
> 
> Here's the full xsl file I'm using:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> 	xmlns:lxslt="http://xml.apache.org/xslt"
> 	xmlns:java="http://xml.apache.org/xslt/java"
> 	xmlns:task="edu.virtualschool.model.Task"
> 	extension-element-prefixes="task"
> 	exclude-result-prefixes="java"
>  >
> <xsl:output method="html"/>
> <xsl:param name="task"></xsl:param>
> 
> <xsl:template match="/task">
> #parse("vel/macros.vel")
> #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:value-of select="task:addPage($task, string(@ident), 
> string(.))" /> </xsl:template>
> 
> <xsl:template 
> match="EmailQuestion|EssayQuestion|NameQuestion|UrlQuestion">
> #<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="*">
> <xsl:copy-of select="."/>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> For completeness, the code that launches the transform (from 
> Task.java)
> 
> TransformerFactory tFactory = 
> TransformerFactory.newInstance(); Transformer transformer = 
> tFactory.newTransformer(new 
> StreamSource(xslFile.toString()));
> transformer.setParameter( "task", this );
> StringWriter sw = new StringWriter();
> transformer.transform(
> 	new StreamSource(xmlFile.toString()),
> 	new StreamResult(sw)
> );
> System.err.println("out:"+sw); // printed and discarded 
> this.xmlModified = xmlFile.lastModified(); this.dvslModified 
> = dvslFile.lastModified();
> 
> And the addPage method (from Task.java). I don't understand the 
> first two arguments; apparently they aren't needed/required/used 
> based on it working after commenting them
> out.
> 
> 	public void addPage(
> 		// 
> org.apache.xalan.extensions.XSLProcessorContext context,
> 		// org.apache.xalan.templates.ElemExtensionCall element,
> 		String ident,
> 		String body
> 	)
> 	{
> 		String pageText =
> 			"#parse(\"vel/macros.vel\")\n"+
> 			"#taskOpening(\""+ident+"\")\n"+
> 			body+"\n"+
> 			"#taskClosing(\""+ident+"\")\n"+
> 			"";
> 		System.err.println("addPage:"+pageText);
> 		pages.add(new Page(this, ident, pageText, new 
> IntegerField(pages.size())));
> 	}
> 


xalan extensions, cont'd.

Posted by Brad Cox <bc...@virtualschool.edu>.
More on the previously posted question. After considerable 
tinkering, the code is actually running, invoking the 
addPage(key, value) method on the task instance I passed as a 
parameter as intended.

The problem is that the value argument, as computed as 
"string(.)", isn't what I want. I want the value to be the 
result of <xsl:apply-templates/>, e.g. not the current node from 
the input, but the node after being transformed by the other 
templates in this file. I don't see how to do this. Can someone 
please help?

Here's the full xsl file I'm using:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:lxslt="http://xml.apache.org/xslt"
	xmlns:java="http://xml.apache.org/xslt/java"
	xmlns:task="edu.virtualschool.model.Task"
	extension-element-prefixes="task"
	exclude-result-prefixes="java"
 >
<xsl:output method="html"/>
<xsl:param name="task"></xsl:param>

<xsl:template match="/task">
#parse("vel/macros.vel")
#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:value-of select="task:addPage($task, string(@ident), string(.))" />
</xsl:template>

<xsl:template 
match="EmailQuestion|EssayQuestion|NameQuestion|UrlQuestion">
#<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="*">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

For completeness, the code that launches the transform (from Task.java)

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new 
StreamSource(xslFile.toString()));
transformer.setParameter( "task", this );
StringWriter sw = new StringWriter();
transformer.transform(
	new StreamSource(xmlFile.toString()),
	new StreamResult(sw)
);
System.err.println("out:"+sw); // printed and discarded
this.xmlModified = xmlFile.lastModified();
this.dvslModified = dvslFile.lastModified();

And the addPage method (from Task.java). I don't understand the 
first two arguments; apparently they aren't needed/required/used 
based on it working after commenting them
out.

	public void addPage(
		// org.apache.xalan.extensions.XSLProcessorContext context,
		// org.apache.xalan.templates.ElemExtensionCall element,
		String ident,
		String body
	)
	{
		String pageText =
			"#parse(\"vel/macros.vel\")\n"+
			"#taskOpening(\""+ident+"\")\n"+
			body+"\n"+
			"#taskClosing(\""+ident+"\")\n"+
			"";
		System.err.println("addPage:"+pageText);
		pages.add(new Page(this, ident, pageText, new 
IntegerField(pages.size())));
	}


Re: xalan ignores xsl:output method="html"?

Posted by Guy McArthur <gu...@guymcarthur.com>.
> I'm not sure if this is a bug. <meta/> should come out as "<meta></meta>"  
> in html, correct? At least that's my interpretation of the spec:
> 
Oops, I meant <meta/> should come out as <meta> (no end tag).