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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing formatted text from XML code.

Status
Not open for further replies.

niallo

Technical User
Jun 12, 2009
8
ZA
Hi there,
Just joined this forum today in the hope that somebody can help me out.

I have an XML file that was exported from a dev environment and I would like to know if there is a way of viewing the content of the file (in a browser window or Word/text doc), without all the tags and formatting info so it can be emailed/printed off for people to read easily?

Just to give you an idea of what I'm dealing with, here's a sample of the code:

<?xml version="1.0" encoding="utf-8" ?>
<page title="Introduction" pType="Text and SWF">
<pText>&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="Helvetica" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"&gt;Group HR is committed to a fair, systematic and consistent approach to recruitment and selection. This is in order to attract, select and retain the most capable staff through open competition on merit.</pText>

So basically all I want to be able to see is:
"Group HR is committed to a fair, systematic and consistent approach to recruitment and selection. This is in order to attract, select and retain the most capable staff through open competition on merit."
And if possible, the page title (Introduction) as well.

I would really appreciate any info at all on how to go about doing this.

Thanks a lot,
Niall
 
Since it seems to be a proper html embedded markup inside the text node(s), the simplest to view in browser is to use xslt to output a html file. Inside the xsl document, maybe counter-intuitively, you set up the xsl:eek:utput element with method="text". That would make it browser-ready.
[tt]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[ignore][/ignore]">
<xsl:eek:utput [blue]method="text"[/blue] omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:apply-templates select="*" />
</xsl:template>
<xsl:template match="page">
<xsl:apply-templates select="pText" />
</xsl:template>
<xsl:template match="pText">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>[/tt]
 
Thanks very much tsuji.
But being a relative novice with all this XML and XSL and XSLT stuff, how do I actually go about using the XSL to convert the XML?
 
Hi tsuji,

It's ok. I just added the line
<?xml-stylesheet type="text/xsl" href="my.xsl"?>
to my XML file and that worked fine. I can view it in my browser now without all the formatting tags.

Thanks very much for your help
Niall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top