943,619 Members | Top Members by Rank

Ad:
Jan 26th, 2009
0

XPath

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Andyyy is offline Offline
4 posts
since Jan 2009
Jan 27th, 2009
0

Re: XPath

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Andyyy is offline Offline
4 posts
since Jan 2009
Jan 28th, 2009
0

Re: XPath

Quote ...
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

Quote ...
<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-
Quote ...
<?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
Quote ...
<?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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: XSLT newbie
Next Thread in XML, XSLT and XPATH Forum Timeline: Converting XPath without namespace to namespace XPath





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC