![]() |
XSL Problem
Hallo zusammen,
ich habe ein Problem mit einem XSL-Template und habe ich folgende XML Datei:
XML-Code:
Und folgende XSL Datei:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?> <catalog> <cd num="0"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <preis> <npreis id="0">10</npreis> <nstaffel id="0">1</nstaffel> <npreis id="1">8</npreis> <nstaffel id="1">2</nstaffel> </preis> <year>1985</year> </cd> <cd num="1"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <preis> <npreis id="0">20</npreis> <nstaffel id="0">1</nstaffel> <npreis id="1">16</npreis> <nstaffel id="1">2</nstaffel> </preis> <year>1985</year> </cd> <cd num="2"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <preis> <npreis id="0">30</npreis> <nstaffel id="0">1</nstaffel> <npreis id="1">24</npreis> <nstaffel id="1">2</nstaffel> </preis> <year>1985</year> </cd> </catalog>
XML-Code:
Nun möchte ich zu jeden Artist beide Preise bekommen und zwar untereinander.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#AAAAAA"> <th align="left">Title</th> <th align="left">Artist</th> <th align="left">Preis</th> <th align="left">Staffel Preis</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> <xsl:for-each select="preis"> <xsl:if test="catalog/cd/preis/nstaffel[@id='1']"> <td colspan="2"></td> </xsl:if> <td><xsl:value-of select="npreis"/></td> <td><xsl:value-of select="nstaffel"/></td> </xsl:for-each> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Leider funktioniert das so wie ich das gemacht habe nicht und ich weiß nicht warum!! Gruß und Dank für eure Hilfe!!! muss!0 |
Re: XSL Problem
Hallo,
kann mir keiner helfen? Gruß muss!0 |
Re: XSL Problem
Hallo,
so ungeduldig, nur weil dir in der vergangenen Nacht noch keiner geantwortet hat? Bist du Herr über das XML-Dokument? Dann überdenke mal deine Struktur:
Code:
Man kann ziemlich viel machen mit XSL-T, aber man kann es sich auch leichter oder schwerer machen. Mit deiner Struktur ist ein xsl:foreach mit dem Selector "preis" nicht sinnvoll.
...
<preis> <npreis id="0">10</npreis> <nstaffel id="0">1</nstaffel> <npreis id="1">8</npreis> <nstaffel id="1">2</nstaffel> </preis> ... Mein Vorschlag wäre:
Code:
Und was deinen gewünschten Output betrifft, so erstelle den HTML-Code mal per Hand, damit ich verstehe auf was du hinaus willst.
...
<preise> <preis staffel="1">10</preis> <preis staffel="2">8</preis> </preise> ... Freundliche Grüße |
Re: XSL Problem
Hi,
danke für die schnelle Antwort! Bin ein bissl im Stress deswegen war ich so ungeduldig!! Also was ich will ist folgendes:
Code:
Gruß und danke schonmal
...
<tr> <td>Empire Burlesque</td> <td>Bob Dylan</td> <td>USA</td> <td>Columbia</td> <td>1985</td> <td>10</td> <td>8</td> </tr> ... muss!0 |
Re: XSL Problem
Wie sind wir denn verblieben, was die Struktur deines XML-Dokuments betrifft?
|
Re: XSL Problem
Hi,
achso hab ich vergessen ja das hab ich geändert! Würde das gerne so machen das es so einfach wie möglich ist!
XML-Code:
Oder etwa so, da bin ich ganz offen! ;-)
<cd num="0">
<title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <preise> <preis> <npreis id="0">10</npreis> <npreis id="1">8</npreis> </preis> <staffel> <nstaffel id="0">1</nstaffel> <nstaffel id="1">2</nstaffel> </staffel> </preise> <year>1985</year> </cd>
XML-Code:
Ich weiß halt nicht was "richtig" ist also ob mein XML dann "valid" ist oder nicht!
<cd num="0">
<title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <preise> <preis> <npreis>10</npreis> <nstaffel>1</nstaffel> </preis> <preis> <npreis>8</npreis> <nstaffel>2</nstaffel> </preis> </preise> <year>1985</year> </cd> EDIT: Hab das so geändert du wie das vorgeschlagen hattest!!! Gruß und Danke muss!0 |
Re: XSL Problem
Liste der Anhänge anzeigen (Anzahl: 1)
Vielleicht hast du meinen Vorschlag gar nicht sehen können?
Code:
In dieser Form würde ich deine Daten umsetzen. Der Preis ist abhängig von einer Staffel und diese Beziehung führt bei mir zu einem Element "preis" mit dem Attribut "staffel".
...
<preise> <preis staffel="1">10</preis> <preis staffel="2">8</preis> </preise> ... Freundliche Grüße |
Re: XSL Problem
Hi,
vielen Dank ich werds sofort probieren!! Gruß muss!0 |
Re: XSL Problem
Noch eine Frage wirft mir sich da auf!
Und zwar was ist wenn ich nicht weiß wieviele Staffelpreise da kommen? Denn dann komme ich mit deiner Lösung nur dann weiter wenn ich die Template Datei immer wieder anpacke!! Und das möchte ich definitiv vermeiden! Gruß muss!0 |
Re: XSL Problem
Deine Daten und dein Layout-Muster haben mir suggeriert, dass du stets genau zwei Staffeln hast. Für eine variable Anzahl Staffeln müsstest du zuerst mal ein neues Layout skizzieren. Was verstehst du eigentlich unter Staffel 1, Staffel 2?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz