|
Subject: RE: AW: [xsl] tricky problem filtering input and counting output From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx> Date: Wed, 23 Feb 2011 07:32:09 +1300 |
Hi Wendell, (& thanks Patrick)
I think running a separate pass to filter the input XML file is the simplest
solution and I will try that straight away. I don't know why it didn't occur
to me already. Strangely (it seems to me) I typed up the whole post and before
wondering what to put in the subject. Now that I look at the subject, I see
that I practically described a two-step solution in half a sentence :-(
But seeing as you asked, here is what is going on with the filtering.
<xsl:param name="filterversions" />
<xsl:param name="filterplatforms" />
<xsl:template name="filter-output">
<xsl:param name="version" />
<xsl:param name="platform" />
<!-- version -->
<xsl:variable name="versionchk">
<xsl:choose>
<xsl:when test="$version != ''">
<xsl:if test="contains($filterversions,$version)">
<xsl:text>Y</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text>Y</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- platform -->
<xsl:variable name="platformchk">
<xsl:choose>
<xsl:when test="$platform != ''">
<xsl:if test="contains($filterplatforms,$platform)">
<xsl:text>Y</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text>Y</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- all together now -->
<xsl:if test="concat($versionchk,$platformchk) = 'YY'">
<xsl:text>Y</xsl:text>
</xsl:if>
</xsl:template>
My original sample had
<xsl:call-template name="filter-output" />
but this template has some parameters of course, which are obtained either
from version/platform attributes on the context element (document or section)
or from higher up the node tree, or from an external document.
<xsl:variable name="select">
<xsl:call-template name="filter-output">
<xsl:with-param name="version">
<xsl:call-template name="get-version" />
</xsl:with-param>
<xsl:with-param name="platform" select="@platform" />
</xsl:call-template>
</xsl:variable>
where get-version is something like this:
<xsl:template name="get-version">
<xsl:variable name="localv">
<xsl:value-of select="(ancestor-or-self::*/@version[. != ''])[last()]" />
</xsl:variable>
<xsl:variable name="external">
<xsl:value-of select="document('catalog.xml',/)/files/file[. =
$me]/@version" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$localv != ''">
<xsl:value-of select="$localv" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$externalv" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
$me is another global parameter identifying the XML file.
The expression for $localv is the way it is because I may need to use min() or
max() instead of last().
And now I expect you to glance at that and say, "yes, pipelining" without a
moment's thought :-)
Cheers
Trevor
-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Wednesday, 23 February 2011 6:25 a.m.
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: AW: [xsl] tricky problem filtering input and counting output
Hi,
On 2/22/2011 9:44 AM, Szabo, Patrick (LNG-VIE) wrote:
> I hope I'm imagining this correctly. Couldn't you filter the input
> before you do the counting ?!
>
> You could dump the document and sections elements you don't need and
> count afterwards.
Yes: Trevor's Gordian knot can be cut by pipelining. Filter the document
first, then run the transformation to generate the output.
A solution in one pass is also possible -- and might even be fairly
clean -- but how it would work best might depend on details of the
filtering requirement. Trevor, you haven't shown us the "filter-output"
template so we don't know what it does and whether it can be refactored
and simplified.
Also, much is possible in XSLT 2.0. For example, if that logic were in a
function instead of a template....
Cheers,
Wendell
--
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: AW: [xsl] tricky problem filter, Wendell Piez | Thread | Re: AW: [xsl] tricky problem filter, Wendell Piez |
| Re: AW: [xsl] tricky problem filter, Wendell Piez | Date | [xsl] Thought i knew this but i gue, russurquhart1 |
| Month |