|
Subject: Re: [xsl] applying templates to attribute value From: mark bordelon <markcbordelon@xxxxxxxxx> Date: Mon, 30 Jun 2008 14:18:24 -0700 (PDT) |
Ken,
Thanks for your quick reply. 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.
Here is what I now have with your cyhanges, alongwith the output:
(I am using Altova).
XML: ==================================
<TEAMS_ASSET_FILE>
<METADATA>
<UOIS>
<GT_ASSET_REQUEST_MD COVERLETTER_TEXT="This is a <b>test</b> of the line break formatting<br />. Did it work?" />
</UOIS>
</METADATA>
</TEAMS_ASSET_FILE>
XSL: ==================================
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:template match="TEAMS_ASSET_FILE">
<xsl:apply-templates select="METADATA/UOIS/GT_ASSET_REQUEST_MD/@COVERLETTER_TEXT" />
</xsl:template>
<!-- formatting in the block -->
<xsl:template match="GT_ASSET_REQUEST_MD/@COVERLETTER_TEXT">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="br">
<fo:block> </fo:block>
</xsl:template>
<xsl:template match="b">
<fo:inline font-weight="bold">
<xsl:apply-templates />
</fo:inline>
</xsl:template>
</xsl:stylesheet>
OUTPUT: ===============================
<?xml version="1.0" encoding="UTF-8"?>This is a <b>test</b> of the line break formatting<br />. Did it work?
--- On Mon, 6/30/08, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> From: G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>
> Subject: Re: [xsl] applying templates to attribute value
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Monday, June 30, 2008, 4:24 PM
> 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: ==================================
> >
> ><TEAMS_ASSET_FILE>
> > <METADATA>
> > <UOIS>
> > <GT_ASSET_REQUEST_MD
> COVERLETTER_TEXT="This is a
> > <b>test</b> of the line
> break formatting<br />.
> > Did it work?" />
> > </UOIS>
> > </METADATA>
> ></TEAMS_ASSET_FILE>
> >
> >XSL: ==================================
> >
> ><xsl:template match="TEAMS_ASSET_FILE">
> > <xsl:apply-templates
> >
> select="./METADATA/UOIS/GT_ASSET_REQUEST_MD/@COVERLETTER_TEXT"
> />
>
> The "./" is redundant above.
>
> ></xsl:template>
> >
> ><!-- 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>
> ><xsl:template match="br">
> > <fo:block> </fo:block>
> ></xsl:template>
> ><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.
> http://www.CraneSoftwrights.com/s/
> Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999
> (F:-0995)
> Male Cancer Awareness Nov'07
> http://www.CraneSoftwrights.com/s/bc
> Legal business disclaimers:
> http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] applying templates to att, G. Ken Holman | Thread | Re: [xsl] applying templates to att, G. Ken Holman |
| Re: [xsl] applying templates to att, G. Ken Holman | Date | RE: [xsl] applying templates to att, Michael Kay |
| Month |