Re: [xsl] use variable in <xsl:if test=

Subject: Re: [xsl] use variable in <xsl:if test=
From: Robert Sösemann <robert.soesemann@xxxxxx>
Date: Sat, 2 Mar 2002 10:04:55 +0100
Thanks Mike,

ok I will explain my problem more specific.
I am writing a java XML wrapper which is able to submit standardized queries
to heteroghenious XML souces.
To translate the queries condition into an Xalan XSL Stylesheet. The user
also provides meta information on things
like:

- If I ask for "author" I am interested in "article" elements
- an also all non"article" supertrees like "number" are interesting

By having those information my programm will return a doc still in the DTD
of the original but only whith interesting fragments.

--- here is a typical query -----

<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml"/>

  <!-- my java program should only set those values to customize the
stylesheet //-->
  <xsl:variable name="condition">*[.//author='C. J. Date']</xsl:variable>
  <xsl:variable name="entity">article</xsl:variable>
  <xsl:variable name="essentialtree">issue</xsl:variable>

  <!-- not elsewhere specified patterns are directly copied //-->
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
 </xsl:copy>
  </xsl:template>

  <!-- also output super tree that is also wanted//-->
  <xsl:template match="node()[name()=$essentialtree]">
 <xsl:if test="$condition">
   <xsl:copy>
   <xsl:apply-templates/>
   </xsl:copy>
 </xsl:if>
  </xsl:template>

  <!-- output the entities with the properties that fullfil the query//-->
  <xsl:template match="node()[name()=$entity]">
 <xsl:if test="$condition">
   <xsl:copy-of select="*"/>
 </xsl:if>
  </xsl:template>

</xsl:transform>
----- Original Message -----
From: "Matt Gushee" <mgushee@xxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, March 02, 2002 1:19 AM
Subject: Re: [xsl] use variable in <xsl:if test=


> On Fri, Mar 01, 2002 at 06:55:41PM -0500, Wendell Piez wrote:
>
> > In the code below, if you are setting the variable at the top level to
be
> > available globally, and you want it to contain any element throughout
that
> > contains an author element whose value is the string "C. J. Date", then
try
> >
> > <xsl:variable name="condition" select="//*[.//author='C. J. Date']"/>
>
> But then, of course, the result would contain the root element -- which
> I'm guessing is not what you want. You are probably trying to distinguish
> between certain elements below the root level that have
> <author>C. J. Date</author> as descendants.
>
> Another problem with this is performance. That may not matter if you are
> doing batch processing of static documents, but if you are generating
> dynamic HTML for your web server, you should try to avoid using '//'
> whenever possible, especially at the top level of the stylesheet. That's
> because the XSLT processor has to search the entire document tree. A
> more specific path, such as:
>
>   /catalog/foo/bar/book[normalize-space(.//author) = 'C. J. Date']
>
> will solve that problem. The normalize-space() function is a good idea
> whenever your stylesheet logic depends on the information contained
> in certain elements. Note that my example above will only work if each
> book has just one author.
>
> If this suggestion and the others people have posted are not enough to
> solve your problem, you might want to post a sample of your source
> document (as well as explaining more of what you want to do).
>
> --
> Matt Gushee
> Englewood, Colorado, USA
> mgushee@xxxxxxxxxxxxx
> http://www.havenrock.com/
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Current Thread