Subject: Re: [xsl] Pairing elements according to attributes with XSLT 1 From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Wed, 29 Jul 2009 13:11:41 +0200 |
As I said have a look at the sorting section of the spec. You may specify what you want in the select statement of <xsl:sort>. Simply replace "<xsl:sort/>" (which is <xsl:sort select="."/>) by this: <xsl:sort select="keyword[@size=$from]"/> $ xsltproc doit.sort2.xsl k3.xml | tidy -q -xml <?xml version="1.0"?>. <MainWordInput xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="entriesResult.xsd" fromSize="small" toSize="tiny"> <Entries> <first>m-Small</first> <second>m-Tiny</second> </Entries> <Entries>> <first>z-Small</first>> <second>z-Tiny</second> </Entries> </MainWordInput> $ Mit besten Gr|_en / Best wishes, Hermann Stamm-Wilbrandt Developer, XML Compiler WebSphere DataPower SOA Appliances ---------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschdftsf|hrung: Erich Baier Sitz der Gesellschaft: Bvblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 Andy Kohn <andydev@xxxxxxxx m> To xsl-list@xxxxxxxxxxxxxxxxxxxxxx 07/29/2009 09:44 cc AM Subject Re: [xsl] Pairing elements Please respond to according to attributes with XSLT 1 xsl-list@xxxxxxxx lberrytech.com Thanks again Hermann. The problem is that putting the sort in there, sorts it using the first keyword, and not the one that is used to search. For example, if I run the XLS with this parameters: <xsl:with-param name="from" select="'small'" /> <xsl:with-param name="to" select="'tiny'" /> With this XML <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE KeywordsInfo [ <!ELEMENT KeywordsInfo (KeywordsEntry+)> <!ELEMENT KeywordsEntry (keyword+)> <!ELEMENT keyword (#PCDATA)> <!ATTLIST keyword size (big|medium|small|tiny) #REQUIRED> ]> <KeywordsInfo> <KeywordsEntry> <keyword size="big">a-Big</keyword> <keyword size="small">z-Small</keyword> <keyword size="tiny">z-Tiny</keyword> </KeywordsEntry> <KeywordsEntry> <keyword size="small">m-Small</keyword> <keyword size="tiny">m-Tiny</keyword> </KeywordsEntry> </KeywordsInfo> It shows z-Small as the first element (and not m-Small), since it's sorting using "<keyword size="big">a-Big</keyword>", although I'm searching from 'small' to 'tiny' Hope it makes sense, thanks, Andy. On Tue, Jul 28, 2009 at 7:40 PM, Hermann Stamm-Wilbrandt<STAMMW@xxxxxxxxxx> wrote: >> I'm still stuck with this sorting... >> >> Can anyone help me out? > > Just insert <xsl:sort> at the right place, here is where you have to: > > $ diff -c2 doit.xsl doit.sort.xsl > *** doit.xsl Tue Jul 28 09:38:50 2009 > --- doit.sort.xsl Tue Jul 28 09:41:16 2009 > *************** > *** 16,19 **** > --- 16,20 ---- > fromSize="{$from}" toSize="{$to}"> > <xsl:for-each select="/KeywordsInfo/KeywordsEntry"> > + <xsl:sort/> > <xsl:variable name="kentry" select="." /> > <xsl:for-each select="keyword[@size=$from]"> > > $ > > You may want to consult the spec (default is " select='.' ") which is > exactly what you want: > http://www.w3.org/TR/xslt#sorting > > > Btw,: > I realized that some IBM email gateway seems to modify my submitted > stylesheets up to being non-XML. I already got confirmation from > xsl-list owner that for the last post I saw this the email reached the > list modified. "doit.xsl" is the stylesheet I submitted last time, > and "doit.save.xsl" is what I just saved via copy and paste from the > old post, here is the strange diff: > > $ diff doit.xsl doit.save.xsl > 2c2 > < xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > --- >> xmlns:xsl=".http://www.w3.org/1999/XSL/Transform";> > 3a4 >> > 14c15 > < <MainWordInput xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " > --- >> <MainWordInput xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "; > 20c21 > < <xsl:variable name="fromkw" select="." /> > --- >> <xsl:variable name="fromkw" select="." />> > > $ > > Mit besten Gr|_en / Best wishes, > > Hermann Stamm-Wilbrandt > Developer, XML Compiler > WebSphere DataPower SOA Appliances > ---------------------------------------------------------------------- > IBM Deutschland Research & Development GmbH > Vorsitzender des Aufsichtsrats: Martin Jetter > Geschdftsf|hrung: Erich Baier > Sitz der Gesellschaft: Bvblingen > Registergericht: Amtsgericht Stuttgart, HRB 243294 > > > > Andy Kohn > <andydev@xxxxxxxx > m> To > xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 07/28/2009 08:36 cc > AM > Subject > Re: [xsl] Pairing elements > Please respond to according to attributes with XSLT 1 > xsl-list@xxxxxxxx > lberrytech.com > > > > > > > > > I'm still stuck with this sorting... > > Can anyone help me out? > > Thanks, > > Andy > > On Fri, Jul 24, 2009 at 12:29 PM, Andy Kohn<andydev@xxxxxxxxx> wrote: >> That works great! thanks a lot for the help. >> >> Now I'm trying to sort it using the data of the node that has attribute > 'from' >> >> For example, with this input, the first one would be AAAA then CCC then > ZZZZ >> >> I tried using <xsl:sort select="keyword[@size=$from]"> but it doesn't >> seem to order it. >> >> <KeywordsInfo> >> <KeywordsEntry> >> <keyword size="big">AAAA</keyword> >> <keyword size="small">table tennis ball</keyword> >> </KeywordsEntry> >> <KeywordsEntry> >> <keyword size="big">ZZZZ</keyword> >> <keyword size="small">chair 1</keyword> >> </KeywordsEntry> >> <KeywordsEntry> >> <keyword size="big">CCC</keyword> >> <keyword size="small">chair 2</keyword> >> </KeywordsEntry> >> </KeywordsInfo> >> >> >> The result I need: >> >> <MainWordInput xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:noNamespaceSchemaLocation="entriesResult.xsd" >> fromSize ="big" >> toSize="small"> >> <Entries> >> <first>AAAA</first> >> <second>table tennis ball</second> >> </Entries> >> <Entries> >> <first>CCC</first> >> <second>chair 2</second> >> </Entries> >> <Entries> >> <first>ZZZZ</first> >> <second>chair 1</second> >> </Entries> >> </MainWordInput> >> >> >> Thanks all!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Pairing elements accordin, Andy Kohn | Thread | Re: [xsl] Pairing elements accordin, Andy Kohn |
[xsl] Emulating XPATH2 range in XSL, Hermann Stamm-Wilbra | Date | Re: [xsl] Emulating XPATH2 range in, Dimitre Novatchev |
Month |