[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT Stylesheet query (newbie)

  • From: Jack Bush <netbeansfan@y...>
  • To: xml-dev@l...
  • Date: Mon, 12 Jan 2009 14:53:21 -0800 (PST)

XSLT Stylesheet query (newbie)

Hi All,

 

I need some advice on how to retrieve the value of 2 attributes (@href, @title) in state.xml as part of transformation as follows:

 

  <?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">

- <head>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

   ………..

</head>

- <body>

  <a shape="rect" name="top" />

+ <div id="container">

- <div id="content">

+ <div id="as1">

+ <div id="alphalinks">

  <h1> Listing of all the states</h1>

+ <p>

- <table class="sresults">

- <tr>

- <td colspan="1" rowspan="1">

  <a shape="rect" href="http://www.abc.com/areas/CA/fairy+land" title="Fairy Land, CA">Fairy Land</a>

  </td>

- <td colspan="1" rowspan="1">

  <a shape="rect" href="http://www.abc.com/areas/CA/wonder+land" title="Wonder Land, CA">Wonder Land</a>

  </td>

……….

</tr>

</body>

</html>

 

  

Below is the content of stateStyleSheet.xsl:

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

<xsl:template match="/">

<html>

<body>

<h2>Transformed State Detail</h2>

<table border="1">

<tr bgcolor="lightblue">

<th align="left">Area Link</th>

<th align="left">Area Name</th>

</tr>

<xsl:for-each select="/html/body/div[@id='content']/table[@class='sresults']/tr/td/a">

<tr>

<td><xsl:value-of select="@href"/></td>

<td><xsl:value-of select="@title"/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

 

</xsl:stylesheet>

 

 

Here is state.java together with XML Catalog to bring everything together:

 

    SAXBuilder stateBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser", false);            

    FileInputStream stateIS = new FileInputStream("E:\\state.xml");

    BufferedInputStream stateBIS = new BufferedInputStream(stateIS);

    Document stateOriginaljdomDocument = stateBuilder.build(stateBIS);

           

    TransformerFactory stateFactory = TransformerFactory.newInstance();

    FileInputStream styleSheetIS = new FileInputStream("E:\\stateStyleSheet.xsl");

    BufferedInputStream styleSheetBIS = new BufferedInputStream(styleSheetIS);

    Transformer stateTransformer = stateFactory.newTransformer(new StreamSource(styleSheetBIS));

       ……

 

Output from transformation process gives:

 

<?xml version="1.0" encoding="UTF-8"?>

<html>

  <body>

    <h2>Transformed State Detail</h2>

    <table border="1">

      <tr bgcolor="lightblue">

        <th align="left">Area Link</th>

        <th align="left">Area Name</th>

      </tr>

    </table>

  </body>

</html>

 

I am not sure whether namespace has anything to do with it. The following XPath statement has worked on the same state.xml document:

 

     XPath stateXPath = XPath.newInstance(

"/ns:html/ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a");

            stateXPath.addNamespace("ns", "http://www.w3.org/1999/xhtml");

 

I am using JDK1.6, Sax6.5.5, TagSoup 1.2, Resolver 1.2, JDOM1.1, Netbeans 6.1 on Windows XP platform.

 

Any assistance would be appreciated.

 

Thanks,

 

Jack

 



Stay connected to the people that matter most with a smarter inbox. http://au.rd.yahoo.com/galaxy/mail/tagline2/*http://au.docs.yahoo.com/mail/smarterinbox.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.