Subject: [xsl] XPath behaves differently when opened by document() From: Jack Bush <netbeansfan@xxxxxxxxxxxx> Date: Mon, 2 Aug 2010 07:11:01 -0700 (PDT) |
Hi All, B 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: B 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 c c <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> B ( 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. B ( 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: B 7 <xsl:for-each select="document($FILE_LIST_PARAM)/ns:html/ns:body/ns:div"> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B 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"> B 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. B 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). B Hope I haven't confused everyone already. B Any suggestion would be much appreciated. Thanks in advance, Jack
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Change Months from Englis, pankaj . c | Thread | Re: [xsl] XPath behaves differently, Wolfgang Laun |
Re: [xsl] Change Months from Englis, pankaj . c | Date | Re: [xsl] XPath behaves differently, Wolfgang Laun |
Month |