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.
It's probably not a good style to post complete source code examples, but there
are many aspects in below script that just seem to tie into one another so I
chose to post the entire code.
To explain a bit more, both, the input and output XML will look somewhat like
this and describe a two-dimensional data structure (e.g. db table contents):
<DataSet>
<ResultSetMetaData>
<ColumnMetaData dtype="number" name="Quantity">
<ColumnMetaData dtype="text" name="Description">
</ResultSetMetaData>
<DataRow type="detail">
<column name="Quantity">255.00</column>
<column name="Description">IBM</column>
</DataRow>
<DataRow type="detail">
<column name="Quantity">100.00</column>
<column name="Description">Sun Microsystems</column>
</DataRow>
</DataSet>
The output XML will have an identical structure, and will either also have
identical content (in the case where $filterstmt = 'ALL') or have some rows
filtered out.
-------------Begin of XSL code example-------------
<?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"/>
<!-- The output method is selected as "text" so that < and > can be
correctly represented in resulting XML as less than and greater than signs -->
<xsl:output method="text"/>
<!-- parameter used to hold the filter statement -->
<xsl:param name="filterstmt"/>
<xsl:template match="DataSet">
<DataSet>
<!--This loop is used to copy all the metadata info to the resulting XML-->
<xsl:for-each select="ResultSetMetaData">
<ResultSetMetaData>
<xsl:apply-templates select="ColumnMetaData"/>
</ResultSetMetaData>
</xsl:for-each>
<!-- If no filter criteria is provided by the user(Example the first time
report is shown) a default filter "ALL" is passed to XSL. This is required to
select a specific xsl:for-each to be used. If filter is "ALL" then all DataRow
are looped where as if a filter is given then it is restricted based on the
filter provided. Two different loops are used since if we use the same for
loop, for both the cases then output when no filter is provided does not have
correct output records. -->
<xsl:choose>
<!--This loop is used to copy all the filtered data to the resulting
XML-->
<xsl:when test="'ALL'=$filterstmt">
<xsl:for-each select="DataRow">
<DataRow type="detail">
<xsl:apply-templates select="column"/>
</DataRow>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<!--This loop is used to copy all the filtered data to the resulting
XML-->
<xsl:for-each select="DataRow[xalan:evaluate($filterstmt)]">
<DataRow type="detail">
<xsl:apply-templates select="column"/>
</DataRow>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</DataSet>
</xsl:template>
<!-- This template is used to copy the contents of element ColumnMetaData-->
<xsl:template match="ColumnMetaData">
<ColumnMetaData name='<xsl:value-of select="@name"/>' dtype='<xsl:value-of
select="@dtype"/>' />
</xsl:template>
<!-- This template is used to copy the contents of element column -->
<xsl:template match="column">
<column name='<xsl:value-of
select="@name"/>'><xsl:apply-templates/></column>
</xsl:template>
</xsl:stylesheet>
This message is for the named person's use only. It may contain sensitive and
private proprietary or legally privileged information. No confidentiality or
privilege is waived or lost by any mistransmission. If you are not the intended
recipient, please immediately delete it and all copies of it from your system,
destroy any hard copies of it and notify the sender. You must not, directly or
indirectly, use, disclose, distribute, print, or copy any part of this message
if you are not the intended recipient. CREDIT SUISSE GROUP and each legal
entity in the CREDIT SUISSE FIRST BOSTON or CREDIT SUISSE ASSET MANAGEMENT
business units of CREDIT SUISSE FIRST BOSTON reserve the right to monitor all
e-mail communications through its networks. Any views expressed in this message
are those of the individual sender, except where the message states otherwise
and the sender is authorized to state them to be the views of any such entity.
Unless otherwise stated, any pricing information given in this message is
indicative only, is subject to change and does not constitute an offer to deal
at any price quoted. Any reference to the terms of executed transactions should
be treated as preliminary only and subject to our formal written confirmation.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list