XML-Nodes mit gleichen Namen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • XML-Nodes mit gleichen Namen

    Hallo Zusammen,
    ich habe diese xml-Datei:

    <?xml version="1.0" encoding="UTF-8"?>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>
    <b id="a3" >
    <s>Table1</s>
    <t state="new">tabelle1</t>
    <comment priority="1">Comment1</comment>
    </b>
    <b id="a4" >
    <s>Table2</s>
    <t state="new">tabelle2</t>
    <comment priority="1">Comment2</comment><special-comment>xy Comment2</special-comment>
    </b>
    </body>
    </a>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>

    <b id="a3" >
    <s>Table3</s>
    <t state="new">tabelle3</t>
    <special-comment priority="1">Comment4</special-comment>
    </b>
    <b id="a4" >
    <s>Table4</s>
    <t xml:lang="de-DE" state="new">tabelle4</t>
    <comment priority="1">Comment6</comment><special-comment>RDComment4</special-comment>
    </b>
    </body>
    </a>
    </xliff>


    und ich muss die so konvertiern:


    <?xml version="1.0" encoding="UTF-8"?>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>
    <b id="a3" >
    <s>Table1</s>
    <t state="new">tabelle1</t>
    <special-comment priority="1">Comment1</special-comment>
    </b>
    <b id="a4" >
    <s>Table2</s>
    <t state="new">tabelle2</t>
    <special-comment priority="1">Comment2, xy Comment2</special-comment>
    </b>
    </body>
    </a>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>

    <b id="a3" >
    <s>Table3</s>
    <t state="new">tabelle3</t>
    <special-comment priority="1">Comment4</special-comment>
    </b>
    <b id="a4" >
    <s>Table4</s>
    <t xml:lang="de-DE" state="new">tabelle4</t>
    <special-comment priority="1">Comment6, RDComment4</special-comment>
    </b>
    </body>
    </a>


    kann jemand mir dabei helfen? Ich bekomme mit meine XSLT-Datei sowas:
    <?xml version="1.0" encoding="UTF-8"?>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>
    <b id="a3" >
    <s>Table1</s>
    <t state="new">tabelle1</t>
    <special-comment priority="1">Comment1</special-comment>
    </b>
    <b id="a4" >
    <s>Table2</s>
    <t state="new">tabelle2</t>
    <special-comment priority="1">Comment2</special-comment><special-comment>xy Comment2</special-comment>
    </b>
    </body>
    </a>
    <a>
    <header><skl><external-file href="skeleton.skl"/></skl></header>
    <body>

    <b id="a3" >
    <s>Table3</s>
    <t state="new">tabelle3</t>
    <special-comment priority="1">Comment4</special-comment>
    </b>
    <b id="a4" >
    <s>Table4</s>
    <t xml:lang="de-DE" state="new">tabelle4</t>
    <special-comment priority="1">Comment6</special-comment><special-comment>RDComment4</special-comment>
    </b>
    </body>
    </a>
    und natürlich die XSLT-Datei sieht so aus:

    <xslt:transform version="1.0"
    xmlns:xslt="http://www.w3.org/1999/XSL/Transform">
    <xslt:key name="com" match="trans-unit" use="comment"/>
    <xslt:template match="@* | node()">
    <xslt:copy>
    <xslt:apply-templates select="@*"/>
    <xslt:apply-templates/>
    </xslt:copy>
    </xslt:template>
    <xslt:template match="a">
    <xslt:copy>
    <xslt:apply-templates select="@*"/>
    <xslt:apply-templates/>
    <xslt:apply-templates select="key('com',
    count(preceding-sibling::a) + 1)/comment"/>
    </xslt:copy>
    </xslt:template>
    <xslt:template match="comment">
    <special-comment>
    <xslt:apply-templates select="@*"/>
    <xslt:apply-templates/>
    </special-comment>
    </xslt:template>
    </xslt:transform>

    Ich freue mich über jede Hinweis.
    Maria

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von m.d ()

  • guten morgen,

    ich hab mal alles in die dafür vorgesehenen codetags geworfen... dann kann mans auch lesen ;)



    Quellcode

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <a>
    3. <header><skl><external-file href="skeleton.skl"/></skl></header>
    4. <body>
    5. <b id="a3" >
    6. <s>Table1</s>
    7. <t state="new">tabelle1</t>
    8. <comment priority="1">Comment1</comment>
    9. </b>
    10. <b id="a4" >
    11. <s>Table2</s>
    12. <t state="new">tabelle2</t>
    13. <comment priority="1">Comment2</comment><special-comment>xy Comment2</special-comment>
    14. </b>
    15. </body>
    16. </a>
    17. <a>
    18. <header><skl><external-file href="skeleton.skl"/></skl></header>
    19. <body>
    20. <b id="a3" >
    21. <s>Table3</s>
    22. <t state="new">tabelle3</t>
    23. <special-comment priority="1">Comment4</special-comment>
    24. </b>
    25. <b id="a4" >
    26. <s>Table4</s>
    27. <t xml:lang="de-DE" state="new">tabelle4</t>
    28. <comment priority="1">Comment6</comment><special-comment>RDComment4</special-comment>
    29. </b>
    30. </body>
    31. </a>
    32. </xliff>
    Alles anzeigen



    Quellcode

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <a>
    3. <header><skl><external-file href="skeleton.skl"/></skl></header>
    4. <body>
    5. <b id="a3" >
    6. <s>Table1</s>
    7. <t state="new">tabelle1</t>
    8. <special-comment priority="1">Comment1</special-comment>
    9. </b>
    10. <b id="a4" >
    11. <s>Table2</s>
    12. <t state="new">tabelle2</t>
    13. <special-comment priority="1">Comment2, xy Comment2</special-comment>
    14. </b>
    15. </body>
    16. </a>
    17. <a>
    18. <header><skl><external-file href="skeleton.skl"/></skl></header>
    19. <body>
    20. <b id="a3" >
    21. <s>Table3</s>
    22. <t state="new">tabelle3</t>
    23. <special-comment priority="1">Comment4</special-comment>
    24. </b>
    25. <b id="a4" >
    26. <s>Table4</s>
    27. <t xml:lang="de-DE" state="new">tabelle4</t>
    28. <special-comment priority="1">Comment6, RDComment4</special-comment>
    29. </b>
    30. </body>
    31. </a>
    Alles anzeigen


    Quellcode

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <a>
    3. <header><skl><external-file href="skeleton.skl"/></skl></header>
    4. <body>
    5. <b id="a3" >
    6. <s>Table1</s>
    7. <t state="new">tabelle1</t>
    8. <special-comment priority="1">Comment1</special-comment>
    9. </b>
    10. <b id="a4" >
    11. <s>Table2</s>
    12. <t state="new">tabelle2</t>
    13. <special-comment priority="1">Comment2</special-comment><special-comment>xy Comment2</special-comment>
    14. </b>
    15. </body>
    16. </a>
    17. <a>
    18. <header><skl><external-file href="skeleton.skl"/></skl></header>
    19. <body>
    20. <b id="a3" >
    21. <s>Table3</s>
    22. <t state="new">tabelle3</t>
    23. <special-comment priority="1">Comment4</special-comment>
    24. </b>
    25. <b id="a4" >
    26. <s>Table4</s>
    27. <t xml:lang="de-DE" state="new">tabelle4</t>
    28. <special-comment priority="1">Comment6</special-comment><special-comment>RDComment4</special-comment>
    29. </b>
    30. </body>
    31. </a>
    Alles anzeigen



    Quellcode

    1. <xslt:transform version="1.0"
    2. xmlns:xslt="http://www.w3.org/1999/XSL/Transform">
    3. <xslt:key name="com" match="trans-unit" use="comment"/>
    4. <xslt:template match="@* | node()">
    5. <xslt:copy>
    6. <xslt:apply-templates select="@*"/>
    7. <xslt:apply-templates/>
    8. </xslt:copy>
    9. </xslt:template>
    10. <xslt:template match="a">
    11. <xslt:copy>
    12. <xslt:apply-templates select="@*"/>
    13. <xslt:apply-templates/>
    14. <xslt:apply-templates select="key('com',
    15. count(preceding-sibling::a) + 1)/comment"/>
    16. </xslt:copy>
    17. </xslt:template>
    18. <xslt:template match="comment">
    19. <special-comment>
    20. <xslt:apply-templates select="@*"/>
    21. <xslt:apply-templates/>
    22. </special-comment>
    23. </xslt:template>
    24. </xslt:transform>
    Alles anzeigen



    thx, truespin
  • die xml ist valid
    habe xliff dazu gemacht


    XML-Quellcode

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <xliff>
    3. <a>
    4. <header>
    5. <skl>
    6. <external-file href="skeleton.skl"/>
    7. </skl>
    8. </header>
    9. <body>
    10. <b id="a3">
    11. <s>Table1</s>
    12. <t state="new">tabelle1</t>
    13. <comment priority="1">Comment1</comment>
    14. </b>
    15. <b id="a4">
    16. <s>Table2</s>
    17. <t state="new">tabelle2</t>
    18. <comment priority="1">Comment2</comment>
    19. <special-comment>xy Comment2</special-comment>
    20. </b>
    21. </body>
    22. </a>
    23. <a>
    24. <header>
    25. <skl>
    26. <external-file href="skeleton.skl"/>
    27. </skl>
    28. </header>
    29. <body>
    30. <b id="a3">
    31. <s>Table3</s>
    32. <t state="new">tabelle3</t>
    33. <special-comment priority="1">Comment4</special-comment>
    34. </b>
    35. <b id="a4">
    36. <s>Table4</s>
    37. <t xml:lang="de-DE" state="new">tabelle4</t>
    38. <comment priority="1">Comment6</comment>
    39. <special-comment>RDComment4</special-comment>
    40. </b>
    41. </body>
    42. </a>
    43. </xliff>
    Alles anzeigen



    XML-Quellcode

    1. <?xml version="1.0"?>
    2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    3. <xsl:output indent="yes" method="xml"/>
    4. <xsl:template match="/">
    5. <xsl:apply-templates select="xliff"/>
    6. </xsl:template>
    7. <xsl:template match="xliff">
    8. <xliff>
    9. <xsl:apply-templates select="a"/>
    10. </xliff>
    11. </xsl:template>
    12. <xsl:template match="a">
    13. <a>
    14. <xsl:apply-templates select="header"/>
    15. <xsl:apply-templates select="body"/>
    16. </a>
    17. </xsl:template>
    18. <xsl:template match="header">
    19. <xsl:copy-of select="."/>
    20. </xsl:template>
    21. <xsl:template match="body">
    22. <xsl:apply-templates select="b"/>
    23. </xsl:template>
    24. <xsl:template match="b">
    25. <b id="{@id}">
    26. <xsl:copy-of select="s"/>
    27. <xsl:copy-of select="t"/>
    28. <special-comment priority="{comment/@priority|special-comment/@priority}">
    29. <xsl:call-template name="comment">
    30. <xsl:with-param name="kn" select="*[contains(local-name(),'comment')]"/>
    31. </xsl:call-template>
    32. </special-comment>
    33. </b>
    34. </xsl:template>
    35. <xsl:template name="comment">
    36. <xsl:param name="kn"/>
    37. <xsl:for-each select="$kn">
    38. <xsl:if test="position()&gt;1">
    39. <xsl:text> , </xsl:text>
    40. </xsl:if>
    41. <xsl:value-of select="."/>
    42. </xsl:for-each>
    43. </xsl:template>
    44. </xsl:stylesheet>
    Alles anzeigen


    Da ich auch in anderen foren zu Hause binsieht man einiges. Denke dran es ist alles freiwillig
    und lösche nicht deine Einträge wie in anderen Foren sonst antwortet dir keiner mehr !!
    ich löschen den Verlauf und lasse Alle dumm streben
    icq 567877710
    Helmut Hagemann
    Derjenige, der sagt: Das geht nicht, soll den nicht stören, der's gerade tut.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von xml_looser ()