xsl-list
[Top] [All Lists]

Re: [xsl] How to transform multiple XML docs with XSLT 2.0 into single doc

2010-06-25 09:18:01
Hi All,
 
Thank you to all your valuable suggestions but I am still not completely clear 
on how to apply document() function to query node-set from secondary documents 
using XPath just yet, even though the concept is simple enough. Let's look at 
an example found on 
http://www.ibm.com/developerworks/xml/library/x-tipcombxslt/ with the following 
documents:
 Listing 1. geneva.xml -- an XML description of a photo
<?xml version="1.0"?>
<ph:photo xmlns:ph="http://ananas.org/2003/tips/photo";>
  <ph:title>The Jet d'Eau fountain</ph:title>
  <ph:location>Geneva</ph:location>
  <ph:date>April 2003</ph:date>
  <ph:description>
    The Jet d'Eau fountain is the most recognizable symbol of Geneva.
    The fountain reaches 140 meters (460 feet) high, roughly the same height
    as the Embassy Suites hotel in Times Square.
  </ph:description>
</ph:photo> 
Listing 2. london.xml -- another XML description of a photo
<?xml version="1.0"?>
<ph:photo xmlns:ph="http://ananas.org/2003/tips/photo";>
  <ph:title>Double-decker bus</ph:title>
  <ph:location>London</ph:location>
  <ph:date>October 2002</ph:date>
  <ph:description>
    An inescapable symbol of London, the double-decker bus is much taller
    than typical buses to carry many passengers through the city's   
    overcrowded streets.
  </ph:description>
</ph:photo> 
Listing 3. index.xml lists the secondary sources
<?xml version="1.0"?>
<ph:index xmlns:ph="http://ananas.org/2003/tips/photo";>
  <ph:title>City sights</ph:title>
  <ph:entry>geneva</ph:entry>
  <ph:entry>london</ph:entry>
  <ph:entry>paris</ph:entry>
  <ph:entry>roma</ph:entry>
</ph:index>  
Listing 4. merge.xsl -- the stylesheet processes the documents listed in the 
main source
1<?xml version="1.0"?>
2<xsl:stylesheet version="1.0"
3             xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
4             xmlns:ph="http://ananas.org/2003/tips/photo";>
5
6 <xsl:output method="html"/>
7
8 <xsl:template match="ph:index">
9   <html>
10    <head><title><xsl:value-of select="ph:title"/></title></head>
11    <xsl:apply-templates/>
12  </html>
13</xsl:template>
14
15<xsl:template match="ph:index/ph:title">
16  <h1><xsl:apply-templates/></h1>
17</xsl:template>
18
19<xsl:template match="ph:entry">
20  <img src="{concat(.,'.jpg')}" align="right"/>
21  <xsl:apply-templates select="document(concat(.,'.xml'))"/>
22  <br clear="right"/>
23</xsl:template>
24
25<xsl:template match="ph:photo/ph:title">
26  <h2><xsl:apply-templates/></h2>
27</xsl:template>
28
29<xsl:template match="ph:location">
30  <h3>in <xsl:apply-templates/></h3>
31</xsl:template>
32
33<xsl:template match="ph:date">
34  <p>Date: <xsl:apply-templates/></p>
35</xsl:template>
36
37<xsl:template match="ph:description">
38  <p><xsl:apply-templates/></p>
39</xsl:template>
40
41</xsl:stylesheet>  
I would like the following clarification on the merge.xsl:
 
( i ) Is it true that lines 8 - 13 retrieves content of /ph:index/ph:title? If 
so what is the purpose of lines 15 - 17?
( ii ) What does line 21 do especially the concat() function and which document 
is it reading from? Is it index.xml? Does it mean that lines 8 - 23 all uses 
the same document as a result from this line? Likewise, where in this 
stylesheet that references the secondary source index.xml?
( iii ) Lines 25 - 39 appears to retrieve content of various nodes in the 
primary source (either geneva.xml orlondon.xml). Exactly which one of them is 
the primary source document? Or is it able to lookup both at the same time?
( iv ) Lines 25 - 39 all uses 
( v ) Lastly, is URI in XSLT is equivalent to filename? e.g. 
document('geneva.xml')
 
Again, this area is very new area to me so your patient would be much 
appreciated.
 
Thanks,
Jack
 <xsl:apply-templates/>. Does this statement navigates to the node-set matched 
within the template only? Or does it also returns the content as well? I 
thought that only <xsl:value-of select="..."/> could accept the target value 
being queried.
----- Original Message ----
From: Andriy Gerasika <andriy(_dot_)gerasika(_at_)gmail(_dot_)com>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Sent: Wed, 23 June, 2010 5:09:22 AM
Subject: Re: [xsl] How to transform multiple XML docs with XSLT 2.0 into single 
doc



    <xsl:template match="/">
      <xsl:for-each select="$data/root/test">
          <xsl:for-each select="."/>
perhaps here should be xsl:value-of??

      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


      


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--