You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Scott DeLoach <sc...@lucent.com> on 2000/06/08 21:43:52 UTC
for-loop in extension
I'm trying to use a javascript for-loop routine in my XSLT, but when I
try to parse the XML/XSLT via XALAN, it returns an error saying "Could
not parse document", pointing the source of the error right at the
line where my for-loop is within the script portion of the XSL.
Can any of you suggest how to resolve this, either as a solution or a
work-around.
Thanks,
Scott DeLoach
Re: for-loop in extension
Posted by Scott DeLoach <sc...@lucent.com>.
Dave:
OK, what I'm trying to do is build an array so that I can refer back
to via a for-loop routine in order to create a list of unique values
in the XML output. Here is a sample of the code:
> <xsl:transform
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
> xmlns:lxslt="http://xml.apache.org/xslt"
> xmlns:user="ext1"
> extension-element-prefixes="user">
>
> <lxslt:component prefix="user" functions="buildarray">
> <lxslt:script lang="javascript" >
>
> var a = new Array();
> var index = 0;
>
> function buildarray (type){
> var found = "false";
> /* Builds an array of unique parameter types */
> for (var i = 0; i < index; i++) {
> if (a[i] == type)
> found = "true";
> }
> if (found == "false") {
> a[index] = type;
> index++;
> return type;
> }
> return null;
> }
>
> </lxslt:script>
> </lxslt:component>
>
> <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
>
> <xsl:template match="/wpcfamilydoc">
> <xsl:element name="data">
> <xsl:apply-templates select="wpcfamily" />
> </xsl:element>
> </xsl:template>
>
> <xsl:template match="wpcfamily">
> <xsl:element name="type">
> <xsl:value-of select="user:buildarray(parameter/@type)" />
> </xsl:element>
> </xsl:template>
>
> </xsl:transform>
If I take out the for-loop, and parse it through XALAN, I get a list
of all the parameter/@types, so I know at this point everything
works. But when I try to parse it through XALAN with the for-loop
routine, it crashes with the following error:
> file:/C:sample.xslt; Line 16; Column 22
> XSL Error: Could not parse sample.xslt document!, Location file:/C:sample.xslt,
> line 16, offset 22
> XSL Error: SAX Exception, Location file:/C:sample.xslt, line 16, offset 22
> Exception in thread "main" org.apache.xalan.xslt.XSLProcessorException: The cont
> ent of elements must consist of well-formed character data or markup.
> at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1630)
> at org.apache.xalan.xslt.XSLTEngineImpl.processStylesheet(XSLTEngineImpl
> .java:722)
> at org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java, Com
> piled Code)
> at transform.main(transform.java:75)
Line 16 is where "for (var i = 0; i < index; i++) {" is located in the
source code.
Any ideas?
Scott DeLoach