开发者

Break lines in XSL

开发者 https://www.devze.com 2023-02-13 22:09 出处:网络
I\'ve tried to use XSL to output the liste of the customer in a XML file but there is no break lines between values

I've tried to use XSL to output the liste of the customer in a XML file but there is no break lines between values

<?xml version="1.0" encoding="UTF-8"?>
<xsl:s开发者_C百科tylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 
  method="html"
  encoding="ISO-8859-1"
  doctype-public="-//W3C//DTD HTML 4.01//EN"
  doctype-system="http://www.w3.org/TR/html4/strict.dtd"
  indent="yes" />
    <xsl:template match="/">
        <xsl:apply-templates select="//client"/>
    </xsl:template>

    <xsl:template match="//client">
     <xsl:value-of select="./nom/." />
    </xsl:template>
</xsl:stylesheet>

The output is

DoeNampelluro

Normallly I want to get

Doe
Nam
Pelluro

I've let indent="yes" but that does not do the job


First of all, the provided XSLT code is quite strange:

<xsl:template match="//client">
  <xsl:value-of select="./nom/." />
</xsl:template>

This is much better written as the equivalent:

<xsl:template match="client">
 <xsl:value-of select="nom" />
</xsl:template>

And the way to output multi-line text is... well, to use the new-line character:

<xsl:template match="client">
 <xsl:value-of select="nom" />
 <xsl:if test="not(position()=last())">
   <xsl:text>&#xA;</xsl:text>
 </xsl:if>
</xsl:template>

Here is a complete transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="client">
  <xsl:value-of select="nom" />
  <xsl:if test="not(position()=last())">
    <xsl:text>&#xA;</xsl:text>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>

when this transformation is applied on the following XML document:

<t>
 <client>
   <nom>A</nom>
 </client>
 <client>
   <nom>B</nom>
 </client>
 <client>
   <nom>C</nom>
 </client>
</t>

the wanted, correct result is produced:

A
B
C

In case you want to produce xHtml output (not just text), then instead of the NL character, a <br> element has to be produced:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="client">
  <xsl:value-of select="nom" />
  <xsl:if test="not(position()=last())">
    <br />
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>

Now, the output is:

A<br/>B<br/>C

and it displays in the browser as:

A
B
C


just add: <br/> tag. it work for me .


<xsl:for-each select="allowedValueList/allowed">
**<br/>**<xsl:value-of select="." />
</xsl:for-each>


I found out that

<xsl:strip-space elements="*" />

does the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消