[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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=" </td> - <td colspan="1" rowspan="1"> <a shape="rect" href="http://www.abc.com/areas/CA/wonder+land" title=" </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> 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|