Subject: Re: [xsl] If/then/else confusion From: Mark Wilson <mark@xxxxxxxxxxxx> Date: Tue, 25 Dec 2012 13:14:26 -0700 |
Here is a short bit of input: <List> <Item> <CatalogName>POFIS-Deskoslovensko</CatalogName> <CatalogNumber>2896</CatalogNumber> <Prefix>A</Prefix> <Article> <Title>New issues</Title> <WholeNumber>56</WholeNumber> <IssueName>Autumn</IssueName> <Year>1989</Year> <Page>76</Page> </Article> </Item> <Item> <CatalogName>SG-Czechoslovakia</CatalogName> <CatalogNumber>2979</CatalogNumber> <Prefix>MS</Prefix> <Article> <Title>New issues</Title> <WholeNumber>56</WholeNumber> <IssueName>Autumn</IssueName> <Year>1989</Year> <Page>76</Page> </Article> </Item> <Item> <CatalogName>POFIS-Deskoslovensko</CatalogName> <CatalogNumber>2897</CatalogNumber> <Article> <Title>New issues</Title> <WholeNumber>56</WholeNumber> <IssueName>Autumn</IssueName> <Year>1989</Year> <Page>76</Page> </Article> </Item> <Item> <CatalogName>SG-Czechoslovakia</CatalogName> <CatalogNumber>2980</CatalogNumber> <Article> <Title>New issues</Title> <WholeNumber>56</WholeNumber> <IssueName>Autumn</IssueName> <Year>1989</Year> <Page>76</Page> </Article> </Item> </List>
Can you provide some sample input for which the Prefix='A' is not working? Are you using XSLT 1 or XSLT 2 (or 3)? It can make a big difference, here.
I'm not sure I understand the problem thoroughly, but remember that in XSLT 2 (and I presume in 3) Prefix != 'A' means "is there any member of the sequence of my children <Prefix> elements whose string value is not 'A'?", not "are all of the members of the sequence of my children <Prefix> elements something other than 'A'?".
I'm not sure that's very well expressed. Here is an experiment you can run to prove the point.
input ----- <?xml version="1.0" encoding="UTF-8"?> <stuff> <sort-us-maybe n="1"> <Prefix>A</Prefix> <Prefix>B</Prefix> <Prefix>C</Prefix> </sort-us-maybe> <sort-us-maybe n="2"> <Prefix>D</Prefix> <Prefix>E</Prefix> <Prefix>F</Prefix> </sort-us-maybe> <sort-us-maybe n="3"> <Prefix>A</Prefix> <Prefix>A</Prefix> <Prefix>A</Prefix> </sort-us-maybe> </stuff>
transform --------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text"/>
<xsl:template match="/stuff"> <xsl:apply-templates select="sort-us-maybe"/> <xsl:text>
</xsl:text> </xsl:template>
<xsl:template match="sort-us-maybe"> <xsl:text>
</xsl:text> <xsl:value-of select="concat( @n, '--')"/> <xsl:text>
Prefix=A: </xsl:text> <xsl:value-of select="Prefix = 'A'"/> <xsl:text>
Prefix!=A: </xsl:text> <xsl:value-of select="Prefix != 'A'"/> <xsl:text>
not(Prefix=A): </xsl:text> <xsl:value-of select="not( Prefix = 'A' )"/> <xsl:text>
not(Prefix!=A): </xsl:text> <xsl:value-of select="not( Prefix != 'A' )"/> </xsl:template>
</xsl:stylesheet>
output ------
1-- Prefix=A: true Prefix!=A: true not(Prefix=A): false not(Prefix!=A): false 2-- Prefix=A: false Prefix!=A: true not(Prefix=A): true not(Prefix!=A): false 3-- Prefix=A: true Prefix!=A: false not(Prefix=A): false not(Prefix!=A): true
Hello, I am trying to modify a sort-select statement I worked out a very long time ago. In the original, I wanted not to sort by a <Prefix> if it were an 'A' and this code does just that:
<xsl:sort select="if( Prefix!='A' ) then Prefix else ''"/>
I am not sure why its positive version does not work: <xsl:sort select="if( Prefix='A' ) then '' else Prefix"/>
However, my new task is to not sort by (1) <Prefix> if the prefix is 'A' or, (2) if the <CatalogName> contains 'SG'.
In the positive the statement look is:
<xsl:sort select="if( Prefix='A' or contains(CatalogName, 'SG')) then '' else Prefix"/>
That statement somehow works for the second filter, [the contains], but not the first [the prefix='A'].
I have no idea what is going on and would appreciate any help I can get. Thanks.
-- Mark Wilson Knihtisk Publishing
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] If/then/else confusion, Syd Bauman | Thread | Re: [xsl] If/then/else confusion, Liam R E Quin |
Re: [xsl] If/then/else confusion, Syd Bauman | Date | Re: [xsl] If/then/else confusion, G. Ken Holman |
Month |