xsl-list
[Top] [All Lists]

RE: Need advise on filtering XSL

2003-01-28 09:00:50
-----Original Message-----
From:     "Stanger, Jan" <jan(_dot_)stanger(_at_)csfb(_dot_)com>
Sent:     Tue, 28 Jan 2003 15:38:42 +0100
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  [xsl] Need advise on filtering XSL

Hello all! This is my first post and unfortunately quite a big 
one as well. I am looking at the following XSL that has been
written by someone else and am trying to understand certain parts
of it. First and foremost, as you can see in the comments the 
output method has been set to text so that < and > would be treated
properly. Elsewhere I have read that this is not a recommended way 
of creating an output XML. Also, both for-each loops in the center
are taking very long for huge XML input documents. Is there
anything that can be made more efficient? Since the output XML 
will be identical in structure to the input one, I thought it
would be possible to use <xsl:copy-of select="."/> in the two
template match functions at the bottom, but it did not work
correctly.

Here is a stylesheet which produces what I think you want. I can't speak to the 
question of speed, since I don't know what your expectations are, nor do I know 
anything about your input file size, processor, RAM, etc.

I first had to properly close the "ColumnMetaData" elements to get a 
well-formed XML document. I think you will find this a simpler approach, and 
I'd be interested to hear if it speeds things up at all.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0" 
xmlns:xalan="http://xml.apache.org/xalan"; exclude-result-prefixes="xalan">
  <xsl:strip-space elements="DataSet ResultSet ResultSetMetaData DataRow 
column"/>

  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:param name="filterstmt" select="'ALL'"/>

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="DataSet">
    <xsl:element name="DataSet">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <xsl:template match="ResultSetMetaData">
    <xsl:element name="ResultSetMetaData">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <xsl:template match="ColumnMetaData">
    <xsl:element name="ColumnMetaData">
      <xsl:attribute name="dtype"><xsl:value-of select="@dtype" 
/></xsl:attribute>
      <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <xsl:template match="DataRow">
    <xsl:choose>
      <xsl:when test="$filterstmt='ALL'">
        <xsl:copy-of select="." />
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="xalan:evaluate($filterstmt)" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="node()|@*" />

</xsl:stylesheet>

-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list