Subject: Re: [xsl] cross reference call of templates in xslt From: "Michael Richter" <A6Sr.CRD@xxxxxxx> Date: Thu, 18 Dec 2008 08:03:57 +0100 |
Hi, Thank you for the help. You are right -i had some errors in my example (cause: i tried to keep it short and simple - my real files are much bigger and complexer). So what you did is ok and works. I have a further issue with it -please see the following input example: <?xml version="1.0" encoding="UTF-8"?> <X> <Daten> <Dokument> <Primaerdokument> <Dateiname>test.txt</Dateiname> </Primaerdokument> <Adress_Informationen> <Absender> <Referenz>d1139077-ed5b-4be8-9eaa-775ab4052c5c</Referenz> </Absender> </Adress_Informationen> </Dokument> <Adresse> <Name> <Name_ID>d1139077-ed5b-4be8-9eaa-775ab4052c5c</Name_ID> <Anrede>a</Anrede> </Name> <Anschrift> <Strasse>i</Strasse> </Anschrift> </Adresse> <Adresse> <Name> <Name_ID>1234567890</Name_ID> <Anrede>another</Anrede> </Name> <Anschrift> <Strasse>just a street</Strasse> </Anschrift> </Adresse> </Daten> </X> I need to get just the one and only correct address-data (in "Adresse") put at possion of ""Referenz" - identified by the value of <Referenz>d1139077-ed5b-4be8-9eaa-775ab4052c5c</Referenz> and <Name_ID>d1139077-ed5b-4be8-9eaa-775ab4052c5c</Name_ID> So i thought i need to give a parameter by the template call: <xsl:apply-template name="adresse" select="../../Daten/Adresse"><xsl:with-param name="referenceID" select="./Adress_Informationen/Absender/Referenz" /></xsl:apply-template> and in the template of "adresse" i am testing <xsl:if test="./Name/Name_ID = $referenceID"> if the "Name_ID" is equal to the Parameter "$referenceID" - but no luck with it. The output is all the data in "Adresse but not included in my formated XML-Tags. Do you have another tip for me? I don't see my mistake. I think it should be possible to filter and select just the one <Adresse>-Tag i need to put the data at position of "Referenz". Here is my actual result (i cut the correct part before "</Primaerdokument>"): ...</Primaerdokument> d1139077-ed5b-4be8-9eaa-775ab4052c5c a i Web 16 dienstlich 1234567890 another just a street </Dokument></XDOMEA> -------- Original-Nachricht -------- > Datum: Wed, 17 Dec 2008 17:37:08 -0500 > Von: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> > An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Betreff: Re: [xsl] cross reference call of templates in xslt > At 2008-12-17 20:29 +0100, Michael Richter wrote: > >Hi, > >I have a XSL-Stylesheet: > >... > >My XML-File as Input: > >... > >Now my Result: > >?xml version="1.0" encoding="UTF-8"?> > ><X> > ><Dokument> > ><Primaerdokument> > ><Dateiname>test (080011538) (080011547).txt</Dateiname> > ></Primaerdokument> > > > > 1234567890 > > a > > i > > </Dokument> > > </XDOMEA> > > I did not get this result running the stylesheet that you posted. > > And the data in your <Dateiname> result element does not match > anything in your source. > > So I just guessed at some of your results. > > >So i need the information of the part of "Adresse" put into the part > >of "Primaerdokument". > > > >I need the following result: > >?xml version="1.0" encoding="UTF-8"?> > ><X> > ><Dokument> > ><Primaerdokument> > ><Dateiname>test (080011538) (080011547).txt</Dateiname> > ></Primaerdokument> > ><Name_ID>1234567890</Name_ID> > ><adr_name>a</adr_name> > ><adr_anrede>i</adr_anrede> > > </Dokument> > > </XDOMEA> > > > >So: Is it possible to do with XSLT what i need? > > Yes ... XSLT is so powerful it can create any XML structure output > from any XML structure input ... the question is how easy is > it? Note I am speaking of structure and vocabulary, not syntax. > > >And what do i need to change in my XSLT-File? I'm doing the > >Transformatino in Java with javax.xml.transform.Transformer > > There were a number of faults in the stylesheet including incorrect > addresses and the use of a named template instead of a matching > template. And even then at the lower level it seemed you were using > non-existent elements. > > I hope the code below helps. > > . . . . . . . . Ken > > t:\ftemp>type richter.xml > <?xml version="1.0" encoding="UTF-8"?> > <X> > <Daten> > <Dokument> > <Primaerdokument> > <Dateiname>test.txt</Dateiname> > </Primaerdokument> > <Adress_Informationen> > <Absender> > <Referenz>d1139077-ed5b-4be8-9eaa-775ab4052c5c</Referenz> > </Absender> > </Adress_Informationen> > </Dokument> > <Adresse> > <Name> > <Name_ID>1234567890</Name_ID> > <Anrede>a</Anrede> > </Name> > <Anschrift> > <Strasse>i</Strasse> > </Anschrift> > </Adresse> > </Daten> > </X> > > t:\ftemp>call xslt richter.xml richter.xsl > <?xml version="1.0" encoding="utf-8"?> > <X xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xdo="http://www.xdomea.de"> > <Dokument> > <Primaerdokument> > <Dateiname>test.txt</Dateiname> > </Primaerdokument> > <Name_ID>1234567890</Name_ID> > <adr_name>a</adr_name> > <adr_anrede>i</adr_anrede> > </Dokument> > </X> > t:\ftemp>type richter.xsl > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xdo="http://www.xdomea.de"> > > <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" /> > > <xsl:template match="/"> > <xsl:for-each select="/X"> > <X> > <xsl:for-each select="Daten/Dokument"> > <Dokument> > <xsl:call-template name="dokument"/> > </Dokument> > </xsl:for-each> > </X> > </xsl:for-each> > </xsl:template> > > <xsl:template name="dokument"> > <Primaerdokument> > <xsl:copy-of select="./Primaerdokument/Dateiname"/> > </Primaerdokument> > <xsl:call-template name="AdressenInfo" /> > </xsl:template> > > <xsl:template name="AdressenInfo"> > <xsl:if test="./Adress_Informationen/Absender/Referenz"> > <xsl:apply-templates select="../../Daten/Adresse"> > <xsl:with-param name="referenceID" > select="./Adress_Informationen/Absender/Referenz" > /> > </xsl:apply-templates> > </xsl:if> > </xsl:template> > > <xsl:template match="Adresse"> > <xsl:param name="referenceID" /> > <Name_ID><xsl:value-of select="./Name/Name_ID" /></Name_ID> > <adr_name><xsl:value-of select="./Name/Anrede" /></adr_name> > <adr_anrede><xsl:value-of select="./Anschrift/Strasse" /></adr_anrede> > </xsl:template> > > </xsl:stylesheet> > > t:\ftemp>rem Done! > > > > -- > Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: > : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 > Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video > Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg > Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE > G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx > Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ > Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc > Legal business disclaimers: http://www.CraneSoftwrights.com/legal -- "Gelebt, aber am Leben vorbei!" Sensationsangebot verldngert: GMX FreeDSL - Telefonanschluss + DSL f|r nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] cross reference call of t, G. Ken Holman | Thread | Re: [xsl] cross reference call of t, Michael Richter |
Re: [xsl] strange error in external, Ganesh Babu N | Date | Re: [xsl] cross reference call of t, Michael Richter |
Month |