Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   XML (https://www.delphipraxis.net/46-xml/)
-   -   Delphi XSL Problem (https://www.delphipraxis.net/98461-xsl-problem.html)

Mussi0 27. Aug 2007 20:00


XSL Problem
 
Hallo zusammen,

ich habe ein Problem mit einem XSL-Template und habe ich folgende XML Datei:

XML-Code:
<?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>
Und folgende XSL Datei:

XML-Code:
<?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>
Nun möchte ich zu jeden Artist beide Preise bekommen und zwar untereinander.

Leider funktioniert das so wie ich das gemacht habe nicht und ich weiß nicht warum!!

Gruß und Dank für eure Hilfe!!!

muss!0

Mussi0 28. Aug 2007 09:06

Re: XSL Problem
 
Hallo,

kann mir keiner helfen?

Gruß

muss!0

marabu 28. Aug 2007 09:30

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:
...
<preis>
    <npreis id="0">10</npreis>
    <nstaffel id="0">1</nstaffel>    
    <npreis id="1">8</npreis>
    <nstaffel id="1">2</nstaffel>          
</preis>
...
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.

Mein Vorschlag wäre:

Code:
...
<preise>
    <preis staffel="1">10</preis>
    <preis staffel="2">8</preis>
</preise>
...
Und was deinen gewünschten Output betrifft, so erstelle den HTML-Code mal per Hand, damit ich verstehe auf was du hinaus willst.

Freundliche Grüße

Mussi0 28. Aug 2007 09:42

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:
...
   <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>
...
Gruß und danke schonmal

muss!0

marabu 28. Aug 2007 12:21

Re: XSL Problem
 
Wie sind wir denn verblieben, was die Struktur deines XML-Dokuments betrifft?

Mussi0 28. Aug 2007 12:40

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:
<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>
Oder etwa so, da bin ich ganz offen! ;-)

XML-Code:
<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>
Ich weiß halt nicht was "richtig" ist also ob mein XML dann "valid" ist oder nicht!

EDIT: Hab das so geändert du wie das vorgeschlagen hattest!!!

Gruß und Danke

muss!0

marabu 28. Aug 2007 13:09

Re: XSL Problem
 
Liste der Anhänge anzeigen (Anzahl: 1)
Vielleicht hast du meinen Vorschlag gar nicht sehen können?

Code:
...
<preise>
    <preis staffel="1">10</preis>
    <preis staffel="2">8</preis>
</preise>
...
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".

Freundliche Grüße

Mussi0 28. Aug 2007 13:13

Re: XSL Problem
 
Hi,

vielen Dank ich werds sofort probieren!!

Gruß

muss!0

Mussi0 28. Aug 2007 13:16

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

marabu 28. Aug 2007 13:32

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 10:49 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz