HTML tags

O

OmyGOD

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
 
S

Soren Kuula

OmyGOD said:
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
 
P

Peter Flynn

OmyGOD said:
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
 

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
474,001
Messages
2,570,251
Members
46,850
Latest member
Brightrs

Latest Threads

Top