Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


retain newline when copying contents of attribute

From: "dkacher" <donald.kacher@------.--->
To: NULL
Date: 3/2/2006 10:18:00 AM
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" >
  <xsl:output 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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent