Anfänger hat Problem mit xsl

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

  • Anfänger hat Problem mit xsl

    Hallo,

    ich soll eine XML-Datei ind ein HTML-Dokument umsetzen, und habe nur Grundkenntnisse und noch keine Erfahrungen.

    Dies XML-Struktur liegt mir vor:

    Quellcode

    1. <OTA_TourInformationNotifRQ xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 CTH_TourInformationNotifRQ.xsd" EchoToken="12345" TimeStamp="2008-03-27T15:52:00" Version="1.000" Target="Test">
    2. <!-- -->
    3. <POS>
    4. <Source>
    5. <RequestorID ID="XYZ" Type="11">
    6. <CompanyName CompanyShortName="CTH">Name des Reiseveranstalters</CompanyName>
    7. </RequestorID>
    8. </Source>
    9. </POS>
    10. <TourInformationItems>...</TourInformationItems>
    11. </OTA_TourInformationNotifRQ>
    Alles anzeigen


    In einem ersten Versuch möchte ich nur das Element "CompanyName" in einem H1-Tag ausgeben und habe dafür dieses Stylesheet erstellt:

    XML-Quellcode

    1. <?xml version="1.0" encoding="iso8859-1"?>
    2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    3. <xsl:template match="/">
    4. <xsl:apply-templates />
    5. </xsl:template>
    6. <xsl:template match="/OTA_TourInformationNotifRQ/POS/Source/RequestorID/CompanyName">
    7. <h1><xsl:value-of select="." /></h1>
    8. </xsl:template>
    9. </xsl:stylesheet>
    Alles anzeigen


    Im Ergebnis wird mir aber der gesamte Inhalt der XML-Datei ausgegeben, wobei Das Element "CaompanyName" nicht mit dem H1-Tag ausgezeichnet wird.

    Was mache ich falsch?

    Gruß, Johannes.
  • sich langsam hoch tasten

    HTML-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="html"/>
    4. <xsl:template match="/">
    5. <html>
    6. <body>
    7. <xsl:apply-templates select="OTA_TourInformationNotifRQ"/>
    8. </body>
    9. </html>
    10. </xsl:template>
    11. <xsl:template match="OTA_TourInformationNotifRQ">
    12. <xsl:apply-templates select="POS"/>
    13. <xsl:apply-templates select="TourInformationItems"/>
    14. </xsl:template>
    15. <xsl:template match="POS">
    16. <xsl:apply-templates select="Source"/>
    17. </xsl:template>
    18. <xsl:template match="Source">
    19. <xsl:apply-templates select="RequestorID"/>
    20. </xsl:template>
    21. <xsl:template match="RequestorID">
    22. <xsl:apply-templates select="CompanyName"/>
    23. </xsl:template>
    24. <xsl:template match="CompanyName">
    25. <h1>
    26. <xsl:value-of select="."/>
    27. </h1>
    28. </xsl:template>
    29. <xsl:template match="TourInformationItems">
    30. <!-- hier gehts weiter falls daten da sind-->
    31. </xsl:template>
    32. </xsl:stylesheet>
    Alles anzeigen
    Helmut Hagemann
    Derjenige, der sagt: Das geht nicht, soll den nicht stören, der's gerade tut.
  • Danke für den Code. Die Vorgehensweise "sich langsam hoch tasten" habe ich verstanden und kann sie nachvollziehen. Bedeutet das auch, dass ich den direkten Pfad nicht angeben kann? Oder ist dein Vorschlag als praktikable Lösung zu verstehen?

    Im Browser wird aber immer noch der gesamte Text-Inhalt der xml-Datei in einem String angezeigt, und nicht nur das Element "CompanyName" und auch ohne HTML-Formatierung.

    Hier die Links: t3test.jochla.de/fileadmin/xml/ota-test.xml | t3test.jochla.de/fileadmin/xml/ota-test.xsl

    Johannes.

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