Re: [xsl] applying templates to attribute value

Subject: Re: [xsl] applying templates to attribute value
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 01 Jul 2008 11:08:30 -0400

At 05:18 PM 6/30/2008, you wrote:
In fact, the select statement was what I started out with, but changed it to apply-templates in order to have the content itself match on the <b> and <br />. Doesn't apply templates force further matching of the matched node? Instead I am still getting the attribute value, untransformed.

Actually, as Ken said, to write the attribute value you should use xsl:value-of. xsl:apply-templates should not work: if it does, your processor is not being conformant, and your code will break in another processor.

This is entirely aside from the question of how you engineer a transform based on the pseudo-markup inside your attribute value.

The key to understanding both of these issues is in the data model. As Ken also said, the tree that XSLT takes as input does not render any structure inside attribute values, but treats them as simple text values. This is in accordance with XML, in which markup as such is prohibited inside attributes, which is why the "markup" you have is escaped with character references to markup delimiters. Whoever has designed your system has decided to ignore this design and pretend that markup inside attributes is as good as markup elsewhere, which it isn't.

Conservative XML designers always prefer elements when they need to represent structure. Sometimes they bend the rules and introduce some sort of structure into attribute values, but when they do, it's always simple enough to parse easily (for example tokenized values, or maybe tokenized values with labels), since this generally has to be done in the application not by the XML parser.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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