Subject: Re: [xsl] preceding sibling From: Mukul Gandhi <mukulgandhi2003@xxxxxxxxxxx> Date: Tue, 20 Apr 2004 03:21:35 +0100 (BST) |
Hi Kaarle, You could use the node-set function to solve the problem. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/person"> <xsl:variable name="rtf"> <person> <xsl:for-each select="notices/notice[@tag = 'NAME']"> <xsl:copy-of select="name"/> </xsl:for-each> </person> </xsl:variable> <xsl:for-each select="xalan:nodeset($rtf)/person/name"> <xsl:if test="givenname = preceding-sibling::name[1]/givenname"> <xsl:value-of select="surname"/> </xsl:if> <xsl:if test="not(givenname = preceding-sibling::name[1]/givenname)"> <xsl:value-of select="givenname"/> <xsl:value-of select="surname"/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Kaarle Kaila <kaarle.kaila@xxxxxx> wrote: > Thank you Andreas for you suggestion. > > >If I interpret correctly, the expression you are > looking for is something > like: > >test="preceding::notice[@tag='NAME'][1]/name/givenname[.=current()]" > >This will be true when the immediately preceding > notice node with an @tag > >equal to 'NAME' has a name/givenname child equal to > the current node. > > I tried this but it compared to names too far back. > The comparision should > be made only to name/givenname elements withing > notice[@tag='NAME'] elements > whithin a person element. > > The suggestion you gave compared also with a name of > the previous person and > that should be avoided. As answer to Mukul's > question : > > The <person> can contain <name> or <notices> and > <notices> contains <notice> > tags and <notice> tags can contain <name>:s. There > is always a <person> tag > as a parent to any <name> or <notices> > > I have started to write an XML Schema to describe > the structure and I stored > the current version at > http://www.kk-software.fi/v20/pikaopas/html/raport.xsd > > I would be greatfull for some advice here. I have > tried to understand the > XPath syntax both using the recommendation at > www.w3c.org and Michael Kays > book but both are rather difficult to read. > > regards > Kaarle > > -- > Kaarle Kaila > email: kaarle dot kaila at iki dot fi > www.iki.fi/kaila > > ----- Original Message ----- > From: "Mukul Gandhi" <mukulgandhi2003@xxxxxxxxxxx> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Sunday, April 18, 2004 1:58 PM > Subject: Re: [xsl] preceding sibling > > > > Hi Kaarle, > > Can you please explain the XML structure? How > does a > > <notice> tag relate to the previous and next > <notice> > > tag? Is there some grouping? > > > > In one <notice> tag, you have'nt mentioned > tag="NAME" > > - > > > > <notice> > > <name> > > <givenname>Lena</givenname> > > <surname>Karamazina</surname> > > </name> > > </notice> > > > > Regards, > > Mukul > > > > --- Kaarle Kaila <kaarle.kaila@xxxxxx> wrote: > > My > > XML file contains data like this: > > > > > > <person sex="F"> > > > <name> > > > <givenname>Lena</givenname> > > > <surname>Karamazina</surname> > > > </name> > > > > > > <notices> > > > <notice tag="NAME"> > > > <name> > > > <givenname>Lena</givenname> > > > <surname>Koski</surname> > > > </name> > > > </notice> > > > > > > <notice tag="BIRT"> > > > <date>1944</date> > > > <place>Tyrvdd</place> > > > </notice> > > > <notice> > > > <name> > > > <givenname>Lena</givenname> > > > <surname>Karamazina</surname> > > > </name> > > > </notice> > > > > > > <notice tag="NAME"> > > > <name> > > > <givenname>Lena-Lisa</givenname> > > > <surname>Karamazina</surname> > > > </name> > > > </notice> > > > </notices> > > > </person> > > > -------------------------------- > > > I want to print the names after each other but > if > > > teh givenname is same as > > > previous one then I want to print only the > surname. > > > > > > The lower part of this xsl section is OK to > compare > > > the name in the person > > > but how should I compare with the givenname of > the > > > previous sibling in > > > notice element with tag="NAME". > > > > > > Any advice would be appreciated. I am having > some > > > difficulties in reading > > > the XSLT book Expressions chapter I guess. > > > > > > > > > > > > <xsl:template match="givenname"> > > > > > > > > > <xsl:choose> > > > <xsl:when > > > > > > test="../../../notice::preceding-sibling[@tag='NAME']=."> > > > <xsl:text> </xsl:text> > > > <xsl:apply-templates/> > > > </xsl:when> > > > > > > <xsl:when > test="ancestor::person/name/givenname=."> > > > </xsl:when> > > > <xsl:otherwise> > > > <xsl:text> </xsl:text> > > > <xsl:apply-templates/> > > > </xsl:otherwise> > > > </xsl:choose> > > > </xsl:template> > > > > > > ------------------ > > > regards > > > Kaarle Kaila > > > -- > > > Kaarle Kaila > > > email: kaarle dot kaila at iki dot fi > > > www.iki.fi/kaila > > > > > > > > ________________________________________________________________________ > > Yahoo! India Matrimony: Find your partner online. > http://yahoo.shaadi.com/india-matrimony/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] preceding sibling, Andreas L. Delmelle | Thread | RE: [xsl] preceding sibling, Andreas L. Delmelle |
[xsl] Reformatting stylesheet (line, Tim Meals | Date | [xsl] feed reader problem, VENKATA_SRIPADA/SCI/ |
Month |