Reading XML file via XSL

S

shailesh_gaikar

All,

Please help in the following.

I am new to XML and XSL.

I have written one XSL as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:USOURCE="USOURCE.DICT">
<xsl:template match="UNIFACE/TABLE/OCC[USOURCE:UTEXT]">
<html>
<h2>Y_WRITE</h2>
<xsl:value-of select="USOURCE:UTEXT" />
</html>
</xsl:template></xsl:stylesheet>

This is to extract UTEXT element contents from one xml file. But these
contents consist of multiple lines. When I run the xml using the above
XSL, multiple lines on in USOURCE:UTEXT get printed on single line.
That is, all the newlines get removed.
Is there any way in which I can preserve the newlines in the text of
XML element and give the same output?
 
M

Martin Honnen

I am new to XML and XSL.

I have written one XSL as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:USOURCE="USOURCE.DICT">
<xsl:template match="UNIFACE/TABLE/OCC[USOURCE:UTEXT]">
<html>
<h2>Y_WRITE</h2>
<xsl:value-of select="USOURCE:UTEXT" />
</html>
</xsl:template></xsl:stylesheet>

This is to extract UTEXT element contents from one xml file. But these
contents consist of multiple lines. When I run the xml using the above
XSL, multiple lines on in USOURCE:UTEXT get printed on single line.
That is, all the newlines get removed.
Is there any way in which I can preserve the newlines in the text of
XML element and give the same output?

Sounds more like a HTML problem to me, in HTML there is the <pre>
element so you might want to use <pre> to wrap the content you have e.g.

<xsl:template match="/">
<html>
<head>
<title>some title</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="USOURCE:UTEXT">
<pre><xsl:value-of select="." /></pre>
</xsl:template>
 
S

shailesh_gaikar

Thank a lot Martin.
That solved my problem.
Any pointers the following?
Instead of displaying HTML output, I want to capture the output in a
text file. Is it possible?
Thanks again

Shailesh
 
M

Martin Honnen

Instead of displaying HTML output, I want to capture the output in a
text file. Is it possible?

Well if you are using an XSLT processor from the command line then you
probably only need to do
processor file.xml file.xsl > output.txt
or similar depending on the syntax that command line shell wants.
I don't know which XSLT processor you use, you might want to check its
documentation for details.
And if you need text output instead of HTML output then you need
<xsl:eek:utput method="text" />
in the stylesheet.
 
S

shailesh_gaikar

I tried using
<xsl:eek:utput method="text" />
But the output opens in browser only.
Also, the same original problem, 'Output on one line', comes. Here I
cannot use <pre>.
Any solution?
Sorry for the trouble.
Thanks in advance

Shailesh
 
M

Martin Honnen

I tried using
<xsl:eek:utput method="text" />
But the output opens in browser only.

Well if you use the browser's XSLT processor then of course it renders
into the browser.
If you want to create a file then you need use a processor you can run
from the command line or using an API in a programming language of your
choice.
 
S

shailesh_gaikar

Thanks a lot for your guidance.
Any good translator, which I can download for this purpose?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top