xsl-list
[Top] [All Lists]

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

2014-09-12 07:09:35
See my comments below.

-----Original Message-----
From: rl(_at_)openmailbox(_dot_)org 
[mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com]
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>