Re: [xsl] applying templates to attribute value

Subject: Re: [xsl] applying templates to attribute value
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Jun 2008 16:24:41 -0400
At 2008-06-30 12:41 -0700, mark bordelon wrote:
Here is the problem in a nutshell, how can I applying a template to string content in an attributes value.

Attribute nodes are leaves of the tree. To act on the content you act on the node's value, unlike an element where you push the children at your stylesheet for processing.

My specific digital asset management application has HTML formatting in an attribute value that I have to transform into fo formating. I have the formatting templates, but I cannot seem to match them to the attribute value.

You are matching the attribute value, you just aren't doing anything with it.

XML: ==================================

<GT_ASSET_REQUEST_MD COVERLETTER_TEXT="This is a &lt;b&gt;test&lt;/b&gt; of the line break formatting&lt;br /&gt;. Did it work?" />

XSL: ==================================

<xsl:template match="TEAMS_ASSET_FILE">
<xsl:apply-templates select="./METADATA/UOIS/GT_ASSET_REQUEST_MD/@COVERLETTER_TEXT" />

The "./" is redundant above.


<!-- formatting in the block -->
<xsl:template match="//GT_ASSET_REQUEST_MD/@COVERLETTER_TEXT">

The "//" is redundant above.

<xsl:apply-templates />

That statement "pushes the children of the node" ... there are no children of the attribute node because it is a leaf in the tree and is attached to an element. As a result, there is nothing added to your result tree.

You want <xsl:value-of select="."/> to add the value of the attribute to the result tree.

<xsl:template match="br">
  <fo:block> </fo:block>
<xsl:template match="b">
  <fo:inline font-weight="bold">
    <xsl:apply-templates select="*|text()"/>

I suspect <xsl:apply-templates/> is sufficient here as that is a synonym for <xsl:apply-templates select="child::node()"/> which is a synonym for <xsl:apply-templates select="*|text()|comment()|processing-instruction"/>

I hope this helps.

. . . . . . . . . . . Ken

Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread