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

Specifying an element from a separate XML file

Subject: Specifying an element from a separate XML file
From: Roy Stafford <sugarpines@xxxxxxxxx>
Date: Wed, 20 May 2009 15:54:59 -0700
 Specifying an element from a separate XML file
Is it possible to specify an element in one input XML file from a
value in a second configuration XML file using XSLT?

For example I have an "input.xml" file with the desired data.
-------------------------------------
<catalog>
  <cd>
    <title>Empire Burlesque@the nightmare</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </cd>
</catalog>
--------------------------------------

And a "configuration.xml" file that states which elements I require.
In this case I wish to output only the title and artist elements and
ignore the country, company and other elements.
--------------------------------------
<configuration>
  <column>title</column>
  <column>artist</column>
</configuration>
--------------------------------------

The XSLT would be something like:
--------------------------------------
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <xsl:for-each select="catalog/cd">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
--------------------------------------

EXCEPT that the <xsl:value-of select="title"/> and <xsl:value-of
select="artist"/> entries would be replaced by the value of each
configuration/column element in configuration.xml file.

My goal is to provide an external configuration file for the
transformation so that the XSLT can be reused without editing.

I'm using Saxon-B 9.1

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.