[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Checking external files based on the attribute val

Subject: Re: Checking external files based on the attribute value
From: Peter Hickman <peter@xxxxxxxxxxxxx>
Date: Wed, 13 Aug 2008 14:37:56 +0100
Re:  Checking external files based on the attribute val
This is a bit clunky but assuming your source data is in source.xml

<?xml version="1.0"?>
<doc>
 <graphic picfile="I970106058X_bulb"/>
 <graphic picfile="I970106058X_dummy"/>
</doc>

and your filelist is in filelist.xml

<?xml version="1.0"?>
<files>
 <file>./970106058X_c01_0002.tif</file>
 <file>./970106058X_c01_0001.tif</file>
 <file>./970106058X_bulb.tif</file>
 <file>./970106058X_0000.tif</file>
 <file>./970106058X_c01_0003.tif</file>
</files>

Then this seems to work.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>


<xsl:variable name="files" select="document('filelist.xml')"/>

 <xsl:template match="/">
   <doc>
     <xsl:apply-templates/>
   </doc>
 </xsl:template>

<xsl:template match="graphic">
<xsl:variable name="file" select="substring-after(concat(@picfile,'.tif'),'I')"/>


   <node picfile="{@picfile}">
     <xsl:attribute name="matched">
       <xsl:choose>
         <xsl:when test="$files/files/file[contains(.,$file)]">
           <xsl:value-of select="true()"/>
         </xsl:when>
         <xsl:otherwise>
           <xsl:value-of select="false()"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:attribute>
   </node>
 </xsl:template>
</xsl:stylesheet>

peter@radish:~/xxx$ xsltproc process.xsl source.xml
<?xml version="1.0"?>
<doc>
 <node picfile="I970106058X_bulb" matched="true"/>
 <node picfile="I970106058X_dummy" matched="false"/>
</doc>
peter@radish:~/xxx$

The $files/files/file[contains(.,$file)] does not seem to want to be converted into a boolean and I couldn't construct a way of getting it to match.

There has got to be a better way!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.