|
Subject: RE: [xsl] Using attributes with XPath From: Mike Ferrando <mikeferrando@xxxxxxxxx> Date: Wed, 23 Aug 2006 22:07:13 -0700 (PDT) |
Jackie,
If you want to write templates for common attributes, you can
distinguish them in two ways (XSLT 1.0).
1. use the mode attributes in the xsl:apply-templates and
xsl:template. This will single out the attribute for particular
transformation for each instance. In your case it would mean a
template for the list/@type attribute and one for each other
instance. You will need to think of your tranformation in catagories
(common transformation vs. uncommon). Use a general template for the
common, and particular templates for what is not common.
<xsl:apply-templates select="@type" mode="list_parent"/>
<xsl:template match="@type" mode="list_parent">
<!-- your cool code here for a list/@type transformation -->
</xsl:template>
2. You can get fancy by using a param and a single template for a
common attribute.
<xsl:apply-templates select="@type">
<xsl:with-param name="parent_x" select="local-name()"/>
</xsl:apply-templates>
<xsl:template match="@type">
<xsl:param name="parent_x"/>
<xsl:choose>
<xsl:when test="string($parent_x)='list'">
<!-- cool code here for list/@type -->
</xsl:when>
<xsl:otherwise>
<!-- cool code here for all the rest -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Hope this helps.
Mike Ferrando
Library Technician
Library of Congress
Washington, DC
202-707-4454
--- Jacqueline Radebaugh <jrad@xxxxxxx> wrote:
> Hello:
>
> Thank you very much for your help. I revised my code so that I
> created two templates for the attributes of the <list> element. It
> looks like:
>
> <!-- list[parent::description] -->
> <xsl:template match="list[parent::description]">
> <fo:list-block>
> <xsl:apply-templates/>
> </fo:list-block>
> </xsl:template>
>
> <xsl:template match="@type[parent::list]">
> <fo:inline font-size="10pt" font-weight="normal">
> <xsl:apply-templates/>
> </fo:inline>
> </xsl:template>
>
> <xsl:template match="@mark[parent::list]">
> <fo:inline font-size="10pt" font-weight="normal">
> <xsl:apply-templates/>
> </fo:inline>
> </xsl:template>
>
> <xsl:template match="item[parent::list]">
> <fo:list-item>
> <fo:list-item-label>
> <fo:block></fo:block>
> </fo:list-item-label>
> <fo:list-item-body>
> <fo:block>
> <xsl:apply-templates/>
> </fo:block>
> </fo:list-item-body>
> </fo:list-item>
> </xsl:template>
>
> I am still obtaining no output of the list. However, when I take
> the attributes off of the <list> element in my source code, i.e.,
>
> <list>
> <item>- The item contains more than one language one of which may
> be a sign language</item>
> <item>- The item is or includes a translation</item>
> <item>- The language of the summaries, abstracts, or accompanying
> material differs from the language of the main item</item>
> <item>- The language of a table of contents differs from the
> language of the main item</item>
> </list>
>
> my XSLT code works. What I am still doing wrong? It is
> definitely related to the attributes of <list> (i.e.,
> type="marked" mark="*").
>
>
> Thank you very much for your help!
>
> Best wishes,
>
>
>
>
> Jackie Radebaugh
>
> Library of Congress
> Network Development & MARC Standards Office
> Washington, DC
> USA
> Phone: +1-202-707-1153
> FAX: +1-202-707-0115
> E-Mail: jrad@xxxxxxx
>
>
> >>> mike@xxxxxxxxxxxx 08/22/06 4:27 PM >>>
> >
> > <xsl:template match="list">
> > <fo:list-block>
> > <xsl:apply-templates select="@*
>
> That will apply-templates to the attributes of the list element,
> but if
> you've written any template rules that match attributes, you
> haven't shown
> them to us.
>
>
> | *[contains(@type,
> > $my_version) or string-length(@type)=0] | text()"/>
>
> That will match children of the list element that have a type
> attribute
> satisfying certain conditions, but in the XML you showed us, no
> children of
> the list element have a type attribute.
>
> | text()"/>
>
> That will match text node children of the list element, but in the
> data you
> showed us, the only text node children of the list element were
> whitespace.
>
> Michael Kay
> http://www.saxonica.com/
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Using attributes with XPa, David Carlisle | Thread | RE: [xsl] Using attributes with XPa, Wendell Piez |
| Re: [xsl] Merging data based on att, Bob Portnell | Date | RE: [xsl] Using attributes with XPa, Mike Ferrando |
| Month |