[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] process xslt and xml spreadsheet via web browser


Subject: Re: [xsl] process xslt and xml spreadsheet via web browser
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Sep 2014 12:09:14 -0000

See my comments below.

> -----Original Message-----
> From: rl@xxxxxxxxxxxxxxx [mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
> Subject: [xsl] process xslt and xml spreadsheet via web browser
>
>
> <?xml version="1.0"?>
> <xsl:stylesheet
> 	version="2.0"
> 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> 	xmlns='http://www.w3.org/1999/xhtml'>
> 	<xsl:output
> 		method="text"
> 		encoding="utf-8"
> 		indent="no"
> 		omit-xml-declaration="yes"
> 		media-type="text/plain"
> 		standalone="yes"
> 		/>
> 	<xsl:template match='Cells'>
> 		<xsl:apply-templates select='Cell'/>
> 	</xsl:template>
> </xsl:stylesheet>
>
> The Jedit text editor was used with the plugin XLST processor (uses Xalan
> Java), which produces the text file (below). Why does the text file contain
> text from nodes outside the nodes 'Cells' and 'Cell'?
>

<snip />

>        <gnm:Cells>
>          <gnm:Cell Row="0" Col="0" ValueType="60">columnnamea</gnm:Cell>
>          <gnm:Cell Row="0" Col="1" ValueType="60">columnnameb</gnm:Cell>


(1) You don't match the Cell elements in your input XML. You have gnm:Cells
and gnm:Cell in your input, which is in another namespace then the default
namespace.

(2) There are many elements you do not match, the default template kicks in,
which just dumps the text nodes.

Solution for (1)
Add that namespace to your stylesheet and add the namespace to your patterns
and XPath expressions, i.e.  match="gnm:Cells" and select="gnm:Cell".

Solution for (2)
Add a "delete-all-except" template to your stylesheet (there are many other
options to solve this one). This will continue processing the nodes
depth-first and will prevent non-matching nodes to output text. The priority
rules for XSLT templates make sure that this template is called only unless
other templates do not match.

<!-- match everything, keep processing, output nothing -->
<xsl:template match="node()">
    <xsl:apply-templates />
</xsl:template>

Cheers,

Abel Braaksma
Exselt XSLT 3.0 Streaming processor
http://exselt.net


Current Thread
Keywords