XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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. Take a look.

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


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS