Reputation: 131
Here is my XML:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfSzablonPismNadrzedny xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SzablonPismNadrzedny NazwaObiektu="Przesylka1">
<Obiekt xsi:type="PrzesylkaWplywajaca">
<NrKancelaryjny>PWP.247</NrKancelaryjny>
<DataWplywu>2012-09-15T00:00:00</DataWplywu>
<ZnakObcy>sdfsdfsdf</ZnakObcy>
....... (ommited)
</Obiekt>
</SzablonPismNadrzedny>
<SzablonPismNadrzedny NazwaObiektu="Sprawa1">
<Obiekt xsi:type="Sprawa">
<ZnakSprawyOpisowy>USC.5351.135.2012</ZnakSprawyOpisowy>
<FunkcjaPrzypisana>FE_SPRA</FunkcjaPrzypisana>
<KontekstProcesowy>EZD</KontekstProcesowy>
.... (ommited)
</Obiekt>
</SzablonPismNadrzedny>
.... (ommited)
Here is my current XSLT:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" version="1.0" encoding="UTF-8"/>
<xsl:template match="SzablonPismNadrzedny[@NazwaObiektu='Sprawa1']">
<xsl:apply-templates select="Obiekt/ZnakSprawyOpisowy"/><xsl:text> </xsl:text>. Skreślono tekst drukowany rubryk I, II, III, IV, V.
</xsl:template>
<xsl:template match="SzablonPismNadrzedny[@NazwaObiektu='Przesylka1']">
Akt sporządzono na podstawie pisma
<xsl:apply-templates select="Obiekt/ZnakObcy"/><xsl:text> </xsl:text> z dnia
<xsl:apply-templates select="Obiekt/DataWplywu"/>
<xsl:text> </xsl:text>. nr
</xsl:template>
</xsl:stylesheet>
Problem is that my output looks like: Akt sporządzono na podstawie pisma value1 z dnia value2. nr value3 Skreślono tekst drukowany rubryk I, II, III, IV, V.
Instead of: value3 Skreślono tekst drukowany rubryk I, II, III, IV, V. Akt sporządzono na podstawie pisma value1 z dnia value2. nr
It takes the order from XML as far as I know. Tried to user priority attribute on xsl:template without results. Anyone knows how can this piece of code be improved?
Upvotes: 1
Views: 422
Reputation: 1796
your XSLT finds <SzablonPismNadrzedny NazwaObiektu="Przesylka1">
first in your input XML that is why it is in the output first.
If you add another template with apply-templates in the correct order I think you get the output you want. Use this XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" version="1.0" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates select="//SzablonPismNadrzedny[@NazwaObiektu='Sprawa1']"/>
<xsl:apply-templates select="//SzablonPismNadrzedny[@NazwaObiektu='Przesylka1']"/>
</xsl:template>
<xsl:template match="SzablonPismNadrzedny[@NazwaObiektu='Sprawa1']">
<xsl:apply-templates select="Obiekt/ZnakSprawyOpisowy"/><xsl:text> </xsl:text>. Skreślono tekst drukowany rubryk I, II, III, IV, V.
</xsl:template>
<xsl:template match="SzablonPismNadrzedny[@NazwaObiektu='Przesylka1']">
Akt sporządzono na podstawie pisma
<xsl:apply-templates select="Obiekt/ZnakObcy"/><xsl:text> </xsl:text> z dnia
<xsl:apply-templates select="Obiekt/DataWplywu"/>
<xsl:text> </xsl:text>. nr
</xsl:template>
</xsl:stylesheet>
and you get this text output:
USC.5351.135.2012 . Skreślono tekst drukowany rubryk I, II, III, IV, V.
Akt sporządzono na podstawie pisma
sdfsdfsdf z dnia
2012-09-15T00:00:00 . nr
Upvotes: 2