Re: [xsl] Output < and > in the attribute from the style sheet

Subject: Re: [xsl] Output < and > in the attribute from the style sheet
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 23 Apr 2012 11:00:22 -0400
Hi Mansour,

As you indicate in your followup question, this is a serialization problem not a transformation problem. Probably the best way of dealing with serialization issues is to clear your head of solutions to transformation problems. :-)

Mike suggested using character maps in XSLT 2.0, which is an excellent idea if it serves. (It will map all incidences of your characters, not just some of them.)

If it doesn't, or under XSLT 1.0, a cleaner solution than writing the entire output as literals is to transform the file without disabling the output escaping, and then post-process it with a separate transformation that would modify just the attributes you wanted to affect.

This would be a modified identity transformation something like this:

<xsl:template match="@conf">
  <xsl:attribute name="conf">
    <xsl:value-of select="." disable-output-escaping="yes"/>
  </xsl:attribute>
</xsl:template>

(plus the identity template).

It comes with a set of caveats explaining why we frown on it (perhaps making allowances for certain carefully controlled circumstances).

Under 2.0 this could be done in a single stylesheet (or in 1.0 with an extension function).

Cheers,
Wendell

On 4/21/2012 7:00 PM, Mansour Al Akeel wrote:
Martin,
thank you. I understand that the '>' doesn't have to be escaped in
this case, and the final results is valid XML. However,
I am wondering about a clean way to prevent the serializer from
escaping it in the attributes.
Currently, the combination of<xsl:text>  and CDATA, is working fine,
but it's ugly as I loose syntax highlight, and indentation.
That is why I am looking for a better a way.

Thank you.

On Sat, Apr 21, 2012 at 7:15 AM, Martin Honnen<Martin.Honnen@xxxxxx> wrote:
Mansour Al Akeel wrote:

In on of the sheets I am working on there is the sign ">" in on of the attributes. I am trying to get this in the resulting XML. So I have this in my template:

        <dependencies>
                <xsl:text disable-output-escaping="yes">
                <![CDATA[
                        <dependency org="org.slf4j" name="slf4j-api"
rev="1.6.4"
conf="provided->*" />
                        <dependency org="org.slf4j" name="slf4j-log4j12"
rev="1.6.4"
conf="compile->*" />
                        <dependency org="log4j" name="log4j" rev="1.2.16"
conf="compile->*,!sources,!javadoc">
                        <exclude module="jmxri" />
                        <exclude module="jmxtools" />
                        </dependency>
                        <dependency org="junit" name="junit" rev="4.8"
conf="test->*" />
                        <dependency org="javax.servlet"
name="javax.servlet-api"
rev="3.0.1" conf="provided->*">
                        <artifact name="javax.servlet-api" type="jar" />
                        </dependency>
                        ]]>
                </xsl:text>

I am using text and CDATA, as you can see in my style sheet.
Is there a better way to output this without escaping the XML and
generate the indented XML ?

-- ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread