Re: [xsl] Testing condition on external XML

Subject: Re: [xsl] Testing condition on external XML
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 04 Aug 2009 18:52:45 -0700
You are very close to a solution.

Thank you for supplying working documents so as
to quickly illustrate the repair.

At 2009-08-04 21:25 -0400, Stanislav Peja wrote:
I am transforming data from a database into an
XML format. I want to run the transformation
only on a subset of all records I have
available. I put identifiers for those records
that I want to transform in a simple external
XML file, which I would like to use as filter.

Only those records should be transformed where
document(acquisition-nums.xml)//acqnum matches

You coded it that way and it did not work. Consider the following description of your requirement:

  "Only those records should be transformed where document(acquisition-
   nums.xml)//acqnum matches each tuple's atom[@name='ObjAccessionNo']."

This has a slightly different spin that solves the problem.

The way I constructed the test does not work and
the whole set from the source file is transformed.

Because you are processing every tuple when any tuple matches the criteria.

I got stuck on this and can't move further. I
appreciate any hint or help on this. I am using Saxon B

Thanks in advance, Standa

Here are the file samples:

File 1 - Source File (records.xml)
File 2 External File (acquisition-nums.xml)
      <xsl:apply-templates select="tuple"/>

This is what I first changed that to:

      <xsl:for-each select="tuple">
        <xsl:if test="atom[@name='ObjAccessionNo']=$acq-num/items/acqnum">
          <xsl:apply-templates select="."/>

... and then made that more succinct by saying:

      <xsl:apply-templates select="tuple[atom[@name='ObjAccessionNo']=

I hope this helps.

. . . . . . . . . . . Ken

t:\ftemp>type records.xml
<table name="ecatalogue">
    <atom name="ObjAccessionNo">2009.030</atom>
    <atom name="ObjTitle">OBJECT TTTLE</atom>
    <atom name="DatDateCreated">2009</atom>
    <atom name="ObjAccessionNo">2009.031</atom>
    <atom name="ObjTitle">OBJECT TTTLE</atom>
    <atom name="DatDateCreated">2009</atom>

t:\ftemp>type acquisition-nums.xml


t:\ftemp>call xslt2 records.xml stanislav.xsl
<?xml version="1.0"
t:\ftemp>type stanislav.xsl
<xsl:stylesheet xmlns:xsl="";
  <xsl:output method="xml" encoding="UTF-8" indent="yes" name="xml"/>
  <xsl:variable name="acq-num" select="document('acquisition-nums.xml')"/>

  <xsl:template match="table[@name='ecatalogue']">
      <xsl:apply-templates select="tuple[atom[@name='ObjAccessionNo']=

  <xsl:template match="tuple">
          <xsl:value-of select="atom[@name='ObjAccessionNo']"/>
        <xsl:value-of select="atom[@name='ObjTitle']"/>


t:\ftemp>rem Done!

Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread