Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transforming an XML document into a tabular report 1

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

We have the following XML document.
Code:
<?xml version='1.0' encoding='UTF-8' ?><autnresponse xmlns:autn='[URL unfurl="true"]http://schemas.autonomy.com/aci/'><action>QUERY</action><response>SUCCESS</response><responsedata>[/URL]
<autn:numhits>2</autn:numhits><autn:hit><autn:reference>[URL unfurl="true"]http://172.26.74.1/static_html_files/sitesearch/_crisis_qa.html</autn:reference><autn:id>3170</autn:id><autn:section>0</autn:section><autn:weight>96.00</autn:weight><autn:database>sitesearch</autn:database><autn:title>Crisis[/URL] Q&A</autn:title><autn:content><DOCUMENT><DREREFERENCE>[URL unfurl="true"]http://172.26.74.1/static_html_files/sitesearch/_crisis_qa.html</DREREFERENCE><DRETITLE>Crisis[/URL] Q&A</DRETITLE><SUMMARY_R>Crisis Q&A</SUMMARY_R></DOCUMENT></autn:content></autn:hit><autn:hit><autn:reference>[URL unfurl="true"]http://172.26.74.1/static_html_files/sitesearch/_sitesearch_reinvent.html</autn:reference><autn:id>3169</autn:id><autn:section>0</autn:section><autn:weight>96.00</autn:weight><autn:database>sitesearch</autn:database><autn:title>Reinvent</autn:title><autn:content><DOCUMENT><DREREFERENCE>http://172.26.74.1/static_html_files/sitesearch/_sitesearch_reinvent.html</DREREFERENCE><DRETITLE>Reinvent</DRETITLE><SUMMARY_R>Explore[/URL] ways to reinvent, restart and get ahead in your career during turbulent times.</SUMMARY_R></DOCUMENT></autn:content></autn:hit><autn:engines><autn:used>0,1,2,3</autn:used></autn:engines></responsedata></autnresponse>

We would like have an XSLT that would produce a tabular report like -

Crisis Q&A, Crisis Q&A
Reinvent, Explore ways to reinvent, restart and get ahead in your career during turbulent times.

Any suggestions?

Regards,
Dan
 
[1] You can do it like this.
[tt]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="[ignore][/ignore]"
xmlns:autn="[ignore][/ignore]"
exclude-result-prefixes="autn"
>
<xsl:eek:utput method="html" />
<xsl:template match="/">
<xsl:apply-templates select="autnresponse" />
</xsl:template>
<xsl:template match="autnresponse">
<xsl:apply-templates select="responsedata" mode="proc" />
</xsl:template>
<xsl:template match="responsedata" mode="proc">
<table border="1">
<xsl:apply-templates select="autn:hit" mode="proc" />
</table>
</xsl:template>
<xsl:template match="autn:hit" mode="proc">
<tr>
<td>
<a href="{autn:content/DOCUMENT/DREREFERENCE}">
<xsl:value-of select="concat('&#xa0;',autn:content/DOCUMENT/DREREFERENCE)" />
</a>
</td>
<td>
<xsl:value-of select="concat('&#xa0;',autn:content/DOCUMENT/DRETITLE)" />
</td>
<td>
<xsl:value-of select="concat('&#xa0;',autn:content/DOCUMENT/SUMMARY_R)" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
[/tt]
[1.1] I put some "mode", just to try to isolate those special templates per processing requirements.

[1.2] Anything related to styling, you have to ask other forums for help.
 
[2] Note that the page posted as such is literally not well-formed. If you've copy-and-paste out of an xml viewer or something, the escape of ampersand (&) is most probably hidden from your view port, such as "Crisis Q&A" should appear in the document as "Crisis Q[red]&-amp;[/red]A" ([red]no hyphen[/red]; added for the only purpose of defeating rendering mechanics of this forum and for you to see.)

[2.1] After editing the above, I come to realize that it may be purely an artifact of posting to this forum resulting in such appearance due to the same reason mentioned above. Hence, this note is for other readers generally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top