xsl-list
[Top] [All Lists]

Re: [xsl] Template doesn't seem to match

2012-07-09 13:59:37
At 2012-07-09 13:25 -0500, russurquhart1(_at_)verizon(_dot_)net wrote:
I have a couple of templates that i thought would handle things but they seem to be working wrong, but i know it must be something i am missing.

The first template:

<xsl:template match="SubSection[@filter='filter1']" priority="1">
        <SubSection>
            <xsl:copy-of select="./Title"/>
<xsl:processing-instruction name="xm-insertion_mark_start"> author="x0167021" time="20120629T115628-0600"</xsl:processing-instruction> <Para>This subsection contains only NDA content and is not available in the public domain.</Para>
            <xsl:processing-instruction name="xm-insertion_mark_end"/>
        </SubSection>

    </xsl:template>

matches a SubSection element that has a filter attribute set to 'filter1', and outputs a Para element saying that entire element is an NDA only section.

The second template:

<xsl:template match="SubSection[*[@filter='filter1']]">
        <SubSection>
            <xsl:apply-templates/>
        </SubSection>
    </xsl:template>

matches a SubSection element that contains any element having a filter attribute set to 'filter1', if so continue processing.

The third template i think should work, but isn't completely. This template should return any remaining SubSection elements, and all that are left at this time, i would think, would be those that have no NDA content.

<xsl:template match="SubSection">
        <SubSection>
            <xsl:copy-of select="./Title"/>
            <Para>This Subsection does not contain any NDA content.</Para>
            <xsl:apply-templates select="SubSection"/>
        </SubSection>
    </xsl:template>

The problem i'm having is that i have an element, in a SubSection, that HAS a filter attribute set to 'filter1', but the second template is NOT catching it.

Right ... because the second template is matching only elements named SubSection. You state "i have an element, in a SubSection", which means you have to match the child of SubSection.

The match pattern "SubSection/*[@filter='filter1']" will match child elements of SubSection, other than another SubSection, that has the attribute. The first template, with the higher priority will catch those element children named SubSection.

If you wanted to match any descendant element in a SubSection, then you would use the "SubSection//*[@filter='filter1']" pattern.

It's getting matched in the third template. Shouldn't the first, second and third templates handle the possibilites?

All three patterns you have match an element named SubSection ... not any element that is in a SubSection.

I'm sure this is something i'm over looking, but i appreciate any help you can provide!

I hope this helps.

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

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--