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

Subject: Re: [xsl] XPath behaves differently when opened by document()
From: Jack Bush <netbeansfan@xxxxxxxxxxxx>
Date: Thu, 5 Aug 2010 07:40:39 -0700 (PDT)
Hi Wolfgang,
 
Thanks for responding to this threat.
 
I have made the
following changes by removing the inner <xsl:for-each> which 
lookup main
source (works) and would like to focus on the outstanding issues:
 
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:apply-templates/>                                                       
                        
 // secondary source
9  
</xsl:for-each>                                                              
                              
 // secondary source
10 </employee-profile>
11
</xsl:template>
12
13 <xsl:template name="finance_initialization"
match="ns:html/ns:body/ns:div">
14   <financial_status>
15   <xsl:variable
name="salary" select="//ns:p[ns:strong='Salary:']"/>
16    
<xsl:apply-templates select="$salary"/>
17   <xsl:if test="empty($salary)">
18     <salary>Unknown</salary>
19   </xsl:if>
       ......
35  
</financial_status>
36 </xsl:template>
37
38 <xsl:template
name="finance_detail" 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>
 
There are 2 URIs passed as parameter $FILE_LIST_PARAM to
document(). ie 
file:///E:/John Smith.xml & file:///E:/Jessica Brown.xml.
 
(
a ) Data from other non-related nodes along the path are been picked up if
<xsl:apply-templates/> is used as seen on line 8, yet XPath queries on both
URIs/files have been unique. ie once only.
( b ) On the other hand, irrelevant
data along the path to the referenced nodes 
<p> are no longer being picked up
(achieved desired effect) if line 8 is 
replaced with <xsl:call-template> as
recommended. However, the down side is that 
the data in each URIs/files are
been picked up (appears to querried both 
finance_initialization &
finance_detail) 3 times.
 
In short, option ( a ) got the data correctly but
also include junk ones while ( 
b ) no longer captured junk yet it is getting
triplicates data. As a result, can 
you explain where this undesireable
looping repetitions have taken place and how 
to resolve it?
 
( c ) There are
<xsl:apply-templates> used within both finance_initialization &
finance_detail templates. Is it necessary to change them over to
<xsl:call-template>?
( d ) What is the purpose of <xsl:template match="ns:p"/>
on line 55 used for? I 
am not clear at what stage that finance_initialization
& finance_detail are 
call/run and in what order?
 
Many thanks again,
Jack
----- Original Message ----
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Tue, 3 August, 2010 12:35:12 AM
Subject:
Re: [xsl] XPath behaves differently when opened by document()

If your
stylesheet is meant to do some lookup in the secondary source based
on data in
the primary source I recommend that you do not try to use
apply-templates for
the lookup but switch to call-template, passing in
parameters taken from the
primary document.

-W


On 2 August 2010 16:34, Wolfgang Laun
<wolfgang.laun@xxxxxxxxx> wrote:
>
> If your stylesheet is meant to do some
lookup in the secondary source based on
> date in the primary source I
recommend that you do not try to use 
>apply-templates
> for the lookup but
switch to call-template, passing in parameters taken from
> the primary
document.
>
> -W
>
> On 2 August 2010 16:11, Jack Bush
<netbeansfan@xxxxxxxxxxxx> wrote:
>>
>> 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[@id='content']/ns:table[@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@xxxxxxxxxxxxxxxxxxxxxx>
>> --~--

Current Thread