[xsl] Testing condition on external XML

Subject: [xsl] Testing condition on external XML
From: Stanislav Pejša <standap@xxxxxxxxx>
Date: Tue, 04 Aug 2009 21:25:26 -0400
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 tuple/atom[@name='ObjAccessionNo'].

The way I constructed the test does not work and the whole set from the source file is transformed. 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)

<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>

File 2 External File (acquisition-nums.xml)



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
<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:if test="tuple/atom[@name='ObjAccessionNo']=$acq-num/items/acqnum">
<xsl:apply-templates select="tuple"/>

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


Current Thread