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

Re: combining multiple documents

Subject: Re: combining multiple documents
From: Steven Ericsson-Zenith <steven@xxxxxxxxxxxxx>
Date: Fri, 25 Jan 2008 08:23:45 -0800
Re:  combining multiple documents
Thanks Andrew but that doesn't help me. I'm using 2.0.

Here is my test/use case, I have three files test.xml is the transformed document, include.xml is the included document and text.xsl is the XSL.

test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<document
   file="include.xml">
   <extra type="introduction"><p>barfoo</p></extra>
</document>

include.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<document>
   <p> foobar </p>
</document>

test.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="2.0">

   <xsl:key
       match="extra"
       name="extra"
       use="@type"/>

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

<xsl:template
match="/document">
<xsl:choose>
<xsl:when
test="@file">
<!-- This works because the extra is in scope -->
<xsl:for-each
select="key('extra','introduction')">
<xsl:apply-templates
select="child::node()"/>
</xsl:for-each>
<xsl:apply-templates
select="doc(@file)"/>
</xsl:when>
<xsl:otherwise>
<!-- But actually we wanted to pass the extra for use here in the second instance of "document" -->
<xsl:for-each
select="key('extra','introduction')">
<xsl:apply-templates
select="child::node()"/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


Your help appreciated.

Sincerely,
Steven


On Jan 24, 2008, at 8:33 AM, Andrew Welch wrote:


On 24/01/2008, Steven Ericsson-Zenith <steven@xxxxxxxxxxxxx> wrote:
The first call to the root node stores a value in a key and the second
call is meant to use the key value.

For the second call to use the key on the first document you need to do a bit of extra work in XSLT 1.0 eg

<xsl:variable name="val" select="val to use in key look up"/>
<xsl:for-each select="$first-doc">
<xsl:apply-templates select="key('keyname', $val)"/>
</

...because the key will only ever be applied to the current document,
so you have to switch back to the first document before making the
call.

XSLT 2.0 remedies this by providing a third argument to key to tell it
which document should be used:

key('keyname', value, $first-doc)

If that's a bit hard to follow, produce the test case and it will be
easier to show you with that.

cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.