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 14:11:51 -0400
At 12:30 PM 7/1/2008, you wrote:
> 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.

actually the default template for attributes does the same as value-of
in this case.

Yes, but if you apply templates when matching an attribute, there are no nodes to apply templates to:

<xsl:template match="@*">

If you apply templates to an attribute, you get its value (by default).

<xsl:template match="*">
  <xsl:apply-templates select="@*/>

(Maybe this was what was meant, in which case I apologize for confusing things, and thanks for the clarification in any case.)

> 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.

Of course it is possible to parse reasonably complicated "quoted html in
attributes" just using xslt if you want to avoid extension functions.
Just bash the attribute value with enough regular expressions and
generate some element nodes... (see htmlparse.xsl for some examples of

But this isn't something I would wish on a beginner. You have to be both adept at plain-text processing and at composing complex logic in XSLT.

BTW, I take it you mean XSLT 2.0, for those regexps w/o extension?

I dare say even an expert will put the code into a library so it doesn't have to be redone. :-)


====================================================================== 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