tags:

views:

43

answers:

1

I am new to this, so please bear with me...

I need to very simply modify content based on a template match: topic/body/section/title

This template match works fine. However, I need this to only happen if the topic element has a title element with the value of "Preface".

Can someone please help with the code?

Here is the code:

<topic>
  <title>Preface</title>
  <body>
    <p>This publication was written for...</p>
    <section>
      <title>Publication Information/Version</title>

Here is the xslt:

<xsl:template match="topic/body/section/title">
        <fo:block xsl:use-attribute-sets="prefacetitle" 
            keep-with-next.within-page="always" 
            keep-together.within-column="always" 
            color="{$docColor}">
            <!--<fo:marker marker-class-name="title-marker"><xsl:value-of select="normalize-space(.)"/></fo:marker>-->
            <xsl:apply-imports/>
        </fo:block>
    </xsl:template>

<xsl:attribute-set name="prefacetitle" >
        <xsl:attribute name="font-family">Trebuchet MS</xsl:attribute>
        <xsl:attribute name="font-size">28pt</xsl:attribute>
        <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="margin-bottom">9pt</xsl:attribute>
        <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
    </xsl:attribute-set>

This code works, but I only want it to modify a section/title when it has an ancestor of topic/title[text()='Preface'].

make sense?

+2  A: 

Without code it is difficult to tell what you want, but maybe something like this:

<xsl:template match="topic[title/text()='Preface']/body/section/title" >

If not, please clarify your question.

Felix Kling
oh, sorry for not being clear. Here is the structure that I need to return.<topic> <title>Preface</title> <body> <p>This publication was written for...</p> <section> <title>Publication Information/Version</title>To clarify - when there is a title (whose text= "Preface") directly under a topic, I need to be able to modify the descendant of section/title.Hopefully this helps. And thanks for the quick feedback.
kman
@kman: The best thing would be if you post your original document, the stylesheet and the desired outcome. But if my answer already helps you it's fine ;)
Felix Kling
Alternatives: `topic[title='Preface']/body/section/title` or `section/title[ancestor::topic[title='Preface']]`
Tomalak
Very nice - thanks for the help Felix King and Tomalak
kman