Search

If I have this piece of xml :

<test>
     <section id="8" handle="test">test</section>
     <entry id="11"> 
`    `<tekst1 mode="formatted">
          <p>Dit is een formatted tekst. </p> 
          <p>En dit is regel 2</p> 
`     `</tekst1> 
</entry>

And I use this xslt :

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="xml" 
   doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
   doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"  
   omit-xml-declaration="yes" 
   encoding="UTF-8" 
   indent="yes" /> 

<xsl:template match="/"> 
    <h1><xsl:value-of select="/data/test/entry/tekst1"/></h1>
</xsl:template>

<:/xsl:stylesheet>

Then the output is this :

<h1>Dit is een formatted tekst. 

En dit is regel 2
</h1>

So the

has disappear. Is this normal behaviour and if so, how can I preserve the <p> and <br> tags ?

value-of is supposed to strip all elements before returning the value. To preserve them you have to use copy-of:

<h1><xsl:copy-of select="/data/test/entry/tekst1/*"/></h1>

Thanks. Learned another thing.

Another tip: don't put <P/>aragraph elements inside <H1/> elements :P

Davidhund : also thanks for this tip.

You can also use this:

<xsl:apply-templates select="tekst1/* | tekst1/text()" mode="html"/>

(you need to include the typography.xsl utility that ships with Symphony). This would output recursively any node and text value of your xml fragment, and you can also override certain elements you need to straighten.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details