471,305 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

HTML tags

Hi,
I am trying to transform XML code like

<text>
This is the first line<br />
This is the second line
</text>

and XSL

<xsl:value-of select="text" />

with XSLTProcessor.(which is provided by an extension of PHP5)

but I can get result like this

This is the first line
This is the second line

how can I keep the <br /> tag during transformation.

Thanks

Aug 15 '05 #1
2 957
OmyGOD wrote:
Hi,
I am trying to transform XML code like

<text>
This is the first line<br />
This is the second line
</text>

and XSL

<xsl:value-of select="text" />

with XSLTProcessor.(which is provided by an extension of PHP5)

how can I keep the <br /> tag during transformation.


The value-of, on a node, will contantenate together all the text nodes
in the subtree rooted in the node, and return that...

Seems you just want to make an identical copy of everything? Or only of
the contents of a text element?

<?xml version='1.0' encoding='utf-8' ?>^M^M
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Don't copy text elements, but do copy their contents -->
<xsl:template match="text">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="text() | *"/>
</xsl:copy>
</xsl:template>

<xsl:template select="text()">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

Soren
Aug 15 '05 #2
OmyGOD wrote:
Hi,
I am trying to transform XML code like

<text>
This is the first line<br />
This is the second line
</text>

and XSL

<xsl:value-of select="text" />

with XSLTProcessor.(which is provided by an extension of PHP5)

but I can get result like this

This is the first line
This is the second line

how can I keep the <br /> tag during transformation.


Don't use value-of: its job is to output content stripped of all markup.
Either use copy-of to preserve the markup, or define a rule for br such as

<xsl:template match="br"><br/></xsl:template>

which simply re-outputs the markup.

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"
Aug 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Donald Firesmith | last post: by
6 posts views Thread by Ludwig77 | last post: by
32 posts views Thread by Cornel Bicutzi | last post: by
82 posts views Thread by Eric Lindsay | last post: by
7 posts views Thread by Xah Lee | last post: by
reply views Thread by Lars Eighner | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.