xsl-list
[Top] [All Lists]

RE: self closing elements with attributes

2004-01-06 13:58:18
Hmm... I'm using Xalan 2.5.2 and when I process this template:

<?xml version="1.0"?>

<xsl:stylesheet 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        version="1.0">
<xsl:output method="xml" indent="yes" xmlns:xalan="http://xml.apache.org/xslt"; 
                xalan:indent-amount="4"/>

<xsl:template match="/">

<xsl:element name="foo">
<xsl:attribute name="bar">
some foo
</xsl:attribute>
</xsl:element>

<foo>
<xsl:attribute name="bar">
some foo
</xsl:attribute>
</foo>

<xsl:element name="foo">
<xsl:attribute name="bar">
some foo
</xsl:attribute>
foo
</xsl:element>

<foo>
<xsl:attribute name="bar">
some foo
</xsl:attribute>
foo
</foo>

</xsl:template>
                
</xsl:stylesheet>

I get:

<?xml version="1.0" encoding="UTF-8"?>
<foo bar="&#10;some foo&#10;"/>
<foo bar="&#10;some foo&#10;"/>
<foo bar="&#10;some foo&#10;">
foo
</foo>
<foo bar="&#10;some foo&#10;">
foo
</foo>


Which seems correct.  What do you get?

Newlines are converted to character referenced in the <xsl:attribute> element. 
See http://www.w3.org/TR/xslt#creating-attributes.

Josh

-----Original Message-----
From: annirack(_at_)shaw(_dot_)ca [mailto:annirack(_at_)shaw(_dot_)ca]
Sent: Tuesday, January 06, 2004 12:22 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] self closing elements with attributes


I'm sure this is a newbie problem, but I can't see what I'm doing wrong.

I have a template like this:

<xsl:element name="foo">
<xsl:attribute name="bar">
some foo
</xsl:attribute>
</xsl:element>

I have also tried:

<foo>
<xsl:attribute name="bar">
some foo
</xsl:attribute>
</foo>

Both give the same result:

<foo bar="some foo">

Which is a problem since it does not close the tag.  If I try

<xsl:element name="foo">
<xsl:attribute name="bar">
some foo
</xsl:attribute>
foo
</xsl:element>

or

<foo>
<xsl:attribute name="bar">
some foo
</xsl:attribute>
foo
</foo>

The result is a correctly closed tag:

<foo bar="some foo">foo</foo>

I have tried this with the same results on several varieties of MSXML, and on 
Xalan-1 and Xalan-2

Is there anything I can do about this that won't require post processing?

--Brendan


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list