Subject: RE: [xsl] Book recommendation (was: xsl:copy - change attributes and tag name) From: "Matias Woloski" <woloski@xxxxxxxx> Date: Sat, 6 Apr 2002 21:46:11 -0300 |
Joerg, that worked perfect! how did you learn all this stuff?? For me xslt is the most difficult thing to learn... I cannot "click" my head to this way of programming. I have to realize that I've never read any book nor tried to learn it deepfully. Do you recommend me one? any pointers? thanks again for all your help! Matias > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Joerg > Heinicke > Sent: sábado, 06 de abril de 2002 21:15 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] xsl:copy - change attributes and tag name > > > For such tasks <xsl:key> is the best approach. > > <xsl:stylesheet> > <!-- build a lookup-table with @IdRef as key --> > <xsl:key name="Indice" match="Indice" use="@IdRef"/> > > <xsl:template match="TreeData"> > <tree> > <xsl:apply-templates select="Indice[not(@IdRef)]"/> > </tree> > </xsl:template> > > <xsl:template match="Indice"> > <tree> > <xsl:apply-templates select="@*"/> > <!-- add here new attributes via <xsl:attribute/> --> > > <!-- applies templates to all attributes and all > elements in the > lookup-table named 'Indice', which have as their @IdRef the > value of the current @IdIndice --> > <xsl:apply-templates select="key('Indice', @IdIndice)"/> > </tree> > </xsl:template> > > <xsl:template match="@*"> > <xsl:copy-of select="."/> > </xsl:template> > > <xsl:template match="@Nombre"> > <xsl:attribute name="text"><xsl:value-of > select="."/></xsl:attribute> > </xsl:template> > </xsl:stylesheet> > > Does this solve all your problems and answer all your questions? > > Joerg > > > Hi folks! > > I have this parent-child xml. > > <TreeData> > > <Indice IdIndice="1" Nombre="Omint Analisis" /> > > <Indice IdIndice="3" IdRef="1" Nombre="OMINT: Precios"/> > > <Indice IdIndice="4" IdRef="1" Nombre="210 / Omint"/> > > <Indice IdIndice="5" Nombre="Swiss Medical Analisis"/> > > <Indice IdIndice="6" IdRef="5" Nombre="Swiss Precios"/> > > <Indice IdIndice="7" IdRef="1" Nombre="310 / Omint"/> > > <Indice IdIndice="8" IdRef="7" Nombre="Cobertura" IdDoc="1"/> > > </TreeData> > > > > What I want to do is putting it into a hierarchical format, which I do > with > > this xsl > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > version="1.0"> > > <xsl:template match="/"> > > <tree> > > <xsl:apply-templates select="TreeData/*[not(@IdRef)]"/> > > </tree> > > </xsl:template> > > > > <xsl:template match="*|@*"> > > <xsl:copy> > > <xsl:apply-templates select="//*[@IdRef = current()/@IdIndice]|@*"/> > > </xsl:copy> > > </xsl:template> > > </xsl:stylesheet> > > > > So I get > > <tree> > > <Indice IdIndice="1" Nombre="Omint Analisis"> > > <Indice IdIndice="3" IdRef="1" Nombre="OMINT: Precios Directos" /> > > <Indice IdIndice="4" IdRef="1" Nombre="210 / Omint" /> > > <Indice IdIndice="7" IdRef="1" Nombre="310 / Omint"> > > <Indice IdIndice="8" IdRef="7" Nombre="Cobertura" IdDoc="1" /> > > </Indice> > > </Indice> > > <Indice IdIndice="5" Nombre="Swiss Medical Analisis"> > > <Indice IdIndice="6" IdRef="5" Nombre="Swiss Precios" /> > > </Indice> > > </tree> > > > > Now I want 3 things: > > 1. instead of generate <Indice> tags I want to get <tree> tags. > > So I would get > > <tree> > > <tree ... /> > > <tree ..> > > <tree ..> > > </tree> > > </tree> > > > > 2. I want to change the "Nombre" attribute to "text" attribute > > So I would have > > <tree text="210/Omint" ...> > > 3. How do I add another attribute to each entry? > > <tree text="..." addedAttr="something"> > > > > thanks in advance! > > Matias > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl:copy - change attribu, Joerg Heinicke | Thread | Re: [xsl] Book recommendation (was:, Joerg Heinicke |
Re: [xsl] xsl:copy - change attribu, Joerg Heinicke | Date | Re: [xsl] Book recommendation (was:, Joerg Heinicke |
Month |