XPath

Please support our XML, XSLT and XPATH advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 4
Reputation: Andyyy is an unknown quantity at this point 
Solved Threads: 0
Andyyy Andyyy is offline Offline
Newbie Poster

XPath

 
0
  #1
Jan 26th, 2009
Hello Developers,

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <p class="abc-srch-Metadata"><span class="abc-srch-URL"><a href="http://www.abc.ac.uk/pub/xyz.aspx?e=20" id="CSR_U_2" title="http://www.abclondon.ac.uk/pub/xyz.aspx?e=20" dir="ltr">http://www.abclondon.ac.uk/pub/xyz.aspx?e=20</a></span>
  2.  
  3. -
  4. 13KB
  5. </p><span class="abc-srch-Icon"><a href="http://www.abclondon.ac.uk/pub/pqr.aspx" id="CSR_IMG_3" title="http://www.abclondon.ac.uk/pub/pqr.aspx"><img align="absmiddle" src="/_layouts/images/html16.gif" border="0" alt="File with extension: aspx"></a></span><span class="abc-srch-Title"><a href="http://www.abclondon.ac.uk/pub/xyz.aspx" title="http://www.abclondon.ac.uk/pub/xyz.aspx">ABC Publications Listing </a><br></span><div class="abc-srch-Description">Alcohol and the <b>lime</b> in perspective

Can any one help me out with the xpath for retreiving title "ABC Publication Listing" and also description "Alcohol and the lime in perspective"

Thanks a lot
Andyyy
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 4
Reputation: Andyyy is an unknown quantity at this point 
Solved Threads: 0
Andyyy Andyyy is offline Offline
Newbie Poster

Re: XPath

 
0
  #2
Jan 27th, 2009
SORTED...but i would like to ask developers here...how come this forum is so dead ???? Is it any good posting any queries in future or is it just a waste of time in this forum...
Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 22
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: XPath

 
0
  #3
Jan 28th, 2009
Can any one help me out with the xpath for retreiving title "ABC Publication Listing" and also description "Alcohol and the lime in perspective"
First of all while giving any example write your xml properly.

if your xml looks like

<test>
<p class="abc-srch-Metadata"><span class="abc-srch-URL"><a href="http://www.abc.ac.uk/pub/xyz.aspx?e=20" id="CSR_U_2" title="http://www.abclondon.ac.uk/pub/xyz.aspx?e=20" dir="ltr">http://www.abclondon.ac.uk/pub/xyz.aspx?e=20</a></span>-13KB</p>
<p><span class="abc-srch-Icon"><a href="http://www.abclondon.ac.uk/pub/pqr.aspx" id="CSR_IMG_3" title="http://www.abclondon.ac.uk/pub/pqr.aspx"><img align="absmiddle" src="/_layouts/images/html16.gif" border="0" alt="File with extension: aspx"/></a></span><span class="abc-srch-Title"><a href="http://www.abclondon.ac.uk/pub/xyz.aspx" title="http://www.abclondon.ac.uk/pub/xyz.aspx">ABC Publications Listing </a><br/></span></p><div class="abc-srch-Description">Alcohol and the <b>lime</b> in perspective</div>
<p class="abc-srch-Metadata"><span class="abc-srch-URL"><a href="http://www.abc.ac.uk/pub/xyz.aspx?e=20" id="CSR_U_2" title="http://www.abclondon.ac.uk/pub/xyz.aspx?e=20" dir="ltr">http://www.abclondon.ac.uk/pub/xyz.aspx?e=20</a></span>-13KB</p>
<p><span class="abc-srch-Icon"><a href="http://www.abclondon.ac.uk/pub/pqr.aspx" id="CSR_IMG_3" title="http://www.abclondon.ac.uk/pub/pqr.aspx"><img align="absmiddle" src="/_layouts/images/html16.gif" border="0" alt="File with extension: aspx"/></a></span><span class="abc-srch-Title"><a href="http://www.abclondon.ac.uk/pub/xyz.aspx" title="http://www.abclondon.ac.uk/pub/xyz.aspx">ABC TEST Listing </a><br/></span></p><div class="abc-srch-Description">Alcohol and Nothing</div>
</test>
And your proposed output should look like-
<?xml version="1.0" encoding="UTF-8" ?>
<chk>
<p>Title: ABC Publications Listing AND Description: Alcohol and the lime in perspective AND Description: Alcohol and Nothing</p>
<p>Title: ABC TEST Listing AND Description: Alcohol and the lime in perspective AND Description: Alcohol and Nothing</p>
</chk>
Then you can use following code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes" />
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<chk>
<xsl:for-each select="//*[@class='abc-srch-Title']">
<p>Title: <xsl:value-of select="." /><xsl:for-each select="//*[@class='abc-srch-Description']"> AND Description: <xsl:value-of select="." /></xsl:for-each></p>
</xsl:for-each>
</chk>
</xsl:template>
</xsl:stylesheet>

Cheers,
Mahesh
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum


Views: 550 | Replies: 2
Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC