xsl-list
[Top] [All Lists]

[xsl] XPath behaves differently when opened by document()

2010-08-02 09:11:46
Hi All,
 
There appears to be 2 undesirable features/effects felt when opening secondary 
document using document() function in XSLT 2.0 (Saxon 9.1) on Windows XP. Let's 
examine the stylesheet in question as follows:
 
1 <xsl:param name="FILE_LIST_PARAM" as="xs:string*" required="no" select="()"/>
2 <xsl:param name="COMPANY_NAME_PARAM"/>
3
4 <xsl:template match="/">
5 <employee-profile>
6 <company_name><xsl:value-of select="$COMPANY_NAME_PARAM"/></company_name>
7 <xsl:for-each select="document($FILE_LIST_PARAM)/ns:html/ns:body/ns:div"> // 
secondary source
8 <xsl:for-each 
select="/ns:html/ns:body/ns:div[(_at_)id='content']/ns:table[(_at_)class='sresults']/ns:tr/ns:td/ns:a">
 // main source
9 <employee_name><xsl:value-of 
select="substring-before(@title,',')"/></employee_name> // main source
10 <employee_address><xsl:value-of select="@href"/></employee_address> // main 
source
11 </xsl:for-each> // main source 
12     <xsl:apply-templates/> // secondary source
13 </xsl:for-each> // secondary source
14 </employee-profile>
15 </xsl:template>
17
18 <xsl:template match="ns:html/ns:body/ns:div">
19 <financial_status>
20 <xsl:variable name="salary" select="//ns:p[ns:strong='Salary:']"/>
21 <xsl:apply-templates select="$salary"/>
22 <xsl:if test="empty($salary)">
23 <salary>Unknown</salary>
24 </xsl:if>
......
35 </financial_status>
36 </xsl:template>
37
38 <xsl:template match="ns:p[ns:strong='Salary:']">
39 <xsl:for-each select="ns:a">
40 <salary><xsl:value-of select="."/></salary>
41 </xsl:template>
..........
55 <xsl:template match="ns:p"/>
56
57 </xsl:stylesheet>
 
( i ) document() needs more specific detail XPath statement to lookup the 
desire 
node. Otherwise, the data for every single subnodes will be retrieved before 
getting to target node. For instance, line 7 would include irrelevant data that 
is part of subnodes along the path of getting to the destination node.
 
( ii ) On the other hand, yet when providing specific XPath instruction would 
appears to query every nodes under the specified branch which is preventing 
their individual templates from being run altogether. Again, if line 7 were to 
changed from:
 
7 <xsl:for-each select="document($FILE_LIST_PARAM)/ns:html/ns:body/ns:div">
                                                    to
7 <xsl:for-each select="document($FILE_LIST_PARAM)/ns:html/ns:body/ns:div/p"> 
or 
<xsl:for-each select="document($FILE_LIST_PARAM)/ns:html/ns:body/ns:div//p"> 

 
where all the data is located in each <p> node but would no longer execute line 
18 - 55, which was the original working stylesheet used to open the same 
document as primary source.
 
In addition, I am also having difficulty getting data (switching between 
documents) from main and secondary documents using nested for-each loop (line 7 
- 11). The result is that only the outer loop (7, 12-13; refer to secondary 
document) is being taken effect but not the internal loop (8 - 11; refer to 
main 
source).
 
Hope I haven't confused everyone already.
 
Any suggestion would be much appreciated.
Thanks in advance,
Jack


      


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

<Prev in Thread] Current Thread [Next in Thread>