Domanda

I'm using Apache FOP and have seen: XSL - Escaping an apostrophe during xsl:when test for escaping characters during xsl:when test.

However, I have problems performing the same equivalence test using xsl:template match

Sample XML

<?xml version="1.0" encoding="UTF-8"?>
<TASKLIST>
    <STEP>
        <STEP_ATTRIBUTE NAME="Step Name">tenants' A &amp; A works</STEP_ATTRIBUTE>
    </STEP>
    <STEP>
        <STEP_ATTRIBUTE NAME="Step Name">test</STEP_ATTRIBUTE>
    </STEP>
</TASKLIST>

Sample XSL

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.1"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
            xmlns:barcode="org.krysalis.barcode4j.xalan.BarcodeExt" 
            xmlns:xalan="http://xml.apache.org" exclude-result-prefixes="barcode xalan">

<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="amps">&amp;</xsl:variable>

<xsl:template match="TASKLIST">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
            <fo:simple-page-master master-name="simple"
                                   page-width="21cm" page-height="29.7cm" margin-left="1cm"
                                   margin-right="1cm">
                <fo:region-body margin-top="0.5cm" />
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="simple">
            <fo:flow flow-name="xsl-region-body">
                <xsl:apply-templates/>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>
<xsl:template match="STEP[STEP_ATTRIBUTE='Step Name'] = concat('tenants', $apos, ' A ', $amps, ' A works')">
    <fo:block>
        Template Match Equal
    </fo:block>
</xsl:template> 
<xsl:template match="STEP[STEP_ATTRIBUTE[@NAME='Step Name'] = 'test']">
    <fo:block>
        <xsl:choose>
            <xsl:when test=".[@NAME='Data Name'] = concat('tenants', $apos, ' A ', $amps, ' A works')">
                When Test Equal
            </xsl:when> 
            <xsl:otherwise>
                When Test NOT Equal
            </xsl:otherwise>
        </xsl:choose>
    </fo:block>
</xsl:template> 
<xsl:template match="STEP">
    <fo:block>
        Catch Non Template Match
    </fo:block>
</xsl:template> 

</xsl:stylesheet>

Output in PDF:

Catch Non Template Match
When Test Equal

The xsl:when test succeeds while template:match fails.

If someone could point me in the right direction or show me what I'm doing wrong, I'd appreciate it greatly.

Many thanks in advance

È stato utile?

Soluzione

Your match attribute has to match a node, but you are performing a test in it which does no return a node (but a boolean result).

You could change it for it to match a node, placing the second part of your expression inside a predicate testing the current node. Perhaps this is what you want:

STEP[STEP_ATTRIBUTE='Step Name'][node() = concat('tenants', $apos, ' A ', $amps, ' A works')]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top