D
dkacher
Hello -
I'm looking for a way to retain newlines when using XSL to copy the
content of an XML attribute.
I have this XML input:
<?xml version="1.0"?>
<A >
<B x = "stuff" y = "line 1
line 2" />
</A>
I would like to write an XSL stylesheet such that it generates html
which, when opened in a browser, looks like this:
Content of y ==
line 1
line 2
==End of content of y
So it seems like my html should look something like this:
<html>
<body>
<p>
Content of y ==
</p><p>line 1
</p><p>line 2
</p><p>== End of content of y
</p>
</body>
</html>
The question is: how do I write an xsl stylesheet to produce this xml?
I've tried copy-of:
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
version = "1.0" >
<xslutput method = "html" />
<xsl:template match="/">
<html><head></head>
<body>Content of y ==<p>
<xsl:apply-templates select="/A/B"/>
== End of content of y</p>
</body>
</html>
</xsl:template>
<xsl:template match = "B" >
<xsl:copy-of select = "@y" />
</xsl:template>
</xsl:stylesheet>
which produces this output:
<html><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
</head>
<body>Content of y ==<p y="line 1 line 2">
== End of content of y</p>
</body>
</html>
This has two problems:
The newline is not retained
The content of the attribute y has been placed as an attribute of the p
element!
Any suggestions on how to tackle this would be appreciated.
Thanks,
- Don
I'm looking for a way to retain newlines when using XSL to copy the
content of an XML attribute.
I have this XML input:
<?xml version="1.0"?>
<A >
<B x = "stuff" y = "line 1
line 2" />
</A>
I would like to write an XSL stylesheet such that it generates html
which, when opened in a browser, looks like this:
Content of y ==
line 1
line 2
==End of content of y
So it seems like my html should look something like this:
<html>
<body>
<p>
Content of y ==
</p><p>line 1
</p><p>line 2
</p><p>== End of content of y
</p>
</body>
</html>
The question is: how do I write an xsl stylesheet to produce this xml?
I've tried copy-of:
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
version = "1.0" >
<xslutput method = "html" />
<xsl:template match="/">
<html><head></head>
<body>Content of y ==<p>
<xsl:apply-templates select="/A/B"/>
== End of content of y</p>
</body>
</html>
</xsl:template>
<xsl:template match = "B" >
<xsl:copy-of select = "@y" />
</xsl:template>
</xsl:stylesheet>
which produces this output:
<html><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
</head>
<body>Content of y ==<p y="line 1 line 2">
== End of content of y</p>
</body>
</html>
This has two problems:
The newline is not retained
The content of the attribute y has been placed as an attribute of the p
element!
Any suggestions on how to tackle this would be appreciated.
Thanks,
- Don