This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: XML criterias
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 3 Jul 2002 15:35:34 +0100
- Subject: RE: [xsl] XML criterias
- Reply-to: xsl-list at lists dot mulberrytech dot com
I think you need a recursive template that applies a filter for one
criterion on each iteration.
<xsl:template name="filter">
<xsl:param name="nodes"/>
<xsl:param name="criteria"/>
<xsl:choose>
<xsl:when test="$criteria">
<xsl:variable name="criterion" select="$criteria[1]"/>
<xsl:call-template name="filter">
<xsl:with param name="criteria" select="criteria[position()>1]"/>
<xsl:with param name="nodes"
select="$nodes[@*[name()=$criterion/@name and
.=$criterion/c:value]"/>
</
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$nodes"/>
</
</xsl:choose>
</
(PS, just saw your title. Call me old-fashioned, but in my dictionary
you have one criterion, two criteria)
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Chen, Gin
> Sent: 02 July 2002 20:29
> To: 'xsl-list@lists.mulberrytech.com'
> Subject: [xsl] XML criterias
>
>
> Hi all,
> I have an XML document that I need to parse out certain
> information. The information that I'm looking for is in a
> separate XML generated with my XSL. So an example would be
> (simplified): //in my xml <?xml version="1.0"
> encoding="UTF-8"?> <?xml-stylesheet type="text/xsl"
> href="C:\NAlert\test.xsl"?> <datarows>
> <rowset id="100" value="100" blah="A"/>
> <rowset id="200" value="200" blah="B"/>
> <rowset id="300" value="100" blah="C"/>
> </datarows>
>
> //inside my xsl
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:c="http://tempuri/criteria">
>
> <xsl:output method="html"/>
>
> <xsl:variable name="para"
> select="document('')/*/c:criteria/c:parameter"/>
>
> <xsl:template match="//datarows/rowset">
> <xsl:copy-of select="@*[name()=$para/@name and
> .=$para/c:value]/parent::*"/> </xsl:template>
>
> <c:criteria>
> <c:parameter name="id">
> <c:value>100</c:value>
> <c:value>200</c:value>
> </c:parameter>
> <c:parameter name="value">
> <c:value>100</c:value>
> </c:parameter>
> </c:criteria>
>
> </xsl:stylesheet>
>
> so i'm basically saying that i want to get all
> datarows/rowsets that have ids of either 100 or 200 AND value
> of 100 the problem is that I'm getting back all rows because
> its returning true if any parameter name/value matches. I
> dont want to hardcode all the parameter names in to the
> select because there could be alot of attributes to check. Is
> there a better way to do this but still keeping it generic?
> Thanks, -Tim
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list