Birgit Hünneke: Tabelle

Hallo,

ich schlage mich jetzt schon seit längerem mit einem Problem herum. Ich muss ein XSL-Stylesheet erstellen, bei dem u.a. folgendes Ergebnis herauskommen soll:

1. Often
2. From time to time
3. Rarely
4. Never
5. DK
6. NA

Hier ist dazu ein Ausschnitt der XML-Datei:
...
<dataDscr>
   <var name="V38">
      <location StartPos="124" width="1"/>
      <labl>Q3 POL DISCUSSION - CONVINCE FRIENDS</labl>
      <qstn ID="Q.3">
 <qstnLit>When you hold a strong opinion, do you ever find yourself persuading your friends, relatives or fellow workers to share your views? Does this happen ...? (READ OUT)</qstnLit>
 <backward>Last trend: EB47.0  Q.3</backward>
      </qstn>
      <catgry>
         <catValu>1</catValu>
  <txt>Often</txt>
      </catgry>
      <catgry>
  <catValu>2</catValu>
  <txt>From time to time</txt>
      </catgry>
      <catgry>
  <catValu>3</catValu>
         <txt>Rarely</txt>
      </catgry>
      <catgry>
  <catValu>4</catValu>
  <txt>Never</txt>
      </catgry>
      <catgry missing="Y">
         <catValu>5</catValu>
  <txt>DK</txt>
      </catgry>
      <catgry missing="Y">
         <catValu>0</catValu>
  <txt>NA</txt>
      </catgry>
...

Wie mache ich das? Sind die Infos dazu ausreichend, oder soll ich einen größeren Ausschnitt nehmen (XML-Datei ist ziemlich weit verzweigt, d.h. die "Pfade" sind recht lang)?

Ich hoffe es kann mir jemand weiterhelfen, ich verzweifle nämlich bald. Entweder es wird nur die erste Zeile gezeigt oder alle <catgry>-Elemente der Datei.

  1. Hi.
    Kannst Du etwas deutlicher erklären, was Du im Zusammnehang mit den XML_Daten sehen willst.
    Mir ist das noch nicht klar.

    bydey

    1. Hallo,

      ich versuche es mal genauer zu erklären. Es handelt sich hier um einen Ausschnitt aus einem Codebuch, das verschiedene Variablen erhält. An dieser Stelle sollen die Werte für die verschiedenen Antworten ausgegeben werden:

      1. Often
      2. Form time to time
      etc. )s.o.

      Mein Problem ist jetzt, dass ich dadurch, dass das Element immer "catgry" heißt, ich mal ALLE Unterelemente ausgegeben bekomme oder nur das erste (1. Often). Wie aber bekomme ich obiges Ergbebnis?
      Die XML-Datei ist ziemlich komplex, daher glaube ich, dass mein Problem in XPath liegt und meine Schwierigkeit ist, den richtigen "Pfad" zu erreichen.

      Ist mein Problem jetzt etwas deutlicher geworden?

      Birgit

      Hi.
      Kannst Du etwas deutlicher erklären, was Du im Zusammnehang mit den XML_Daten sehen willst.
      Mir ist das noch nicht klar.

      bydey

      1. Ok.

        1. Often
        2. Form time to time
          etc. )s.o.

        Wie sehen Deine falschen Antworten aus?

        bydey

        1. Mein letzter Versuch war schon eine kleine Annäherung, denn u.a. hatt ich das Ergebnis dabei, aber es wurde noch viel mehr davor und dahinter ausgegeben, was ich hier gar nicht brauche. Wie gesagt, ich galube ich sollte mir das "XPath-Kapitel" nochmal ganz gründlich durchlesen! Also hier eine meiner Antworten:

          <?xml version="1.0" encoding="ISO-8859-1"?>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

          <xsl:template match="dataDscr">
             <html>
                <body>
                   <h1>Tabelle Variable 38</h1>
                   <table border="1">
                      <tr>
                         <td>(Wert)</td><td>(Antwort)</td>
                      </tr>
                      <xsl:apply-templates select="var" />
                   </table>
                </body>
             </html>
          </xsl:template>

          <xsl:template match="catgry">
             <tr>
                <td><xsl:apply-templates select="catValu" />xsl:text.</xsl:text></td>

          <td><xsl:apply-templates select="txt" /></td>
             </tr>
          </xsl:template>
          </xsl:stylesheet>

          Hilft Dir das weiter ohne komplette XML-Datei?

          Birgit

          Ok.

          1. Often
          2. Form time to time
            etc. )s.o.

          Wie sehen Deine falschen Antworten aus?

          bydey

          1. HI.
            Jetzt häng mir einfach ein Stück vom falschen Ergebnis mit dran!

            bydey

            <?xml version="1.0" encoding="ISO-8859-1"?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

            <xsl:template match="dataDscr">
               <html>
                  <body>
                     <h1>Tabelle Variable 38</h1>
                     <table border="1">
                        <tr>
                           <td>(Wert)</td><td>(Antwort)</td>
                        </tr>
                        <xsl:apply-templates select="var" />
                     </table>
                  </body>
               </html>
            </xsl:template>

            <xsl:template match="catgry">
               <tr>
                  <td><xsl:apply-templates select="catValu" />xsl:text.</xsl:text></td>

            <td><xsl:apply-templates select="txt" /></td>
               </tr>
            </xsl:template>
            </xsl:stylesheet>

            Hilft Dir das weiter ohne komplette XML-Datei?

            Birgit

            Ok.

            1. Often
            2. Form time to time
              etc. )s.o.

            Wie sehen Deine falschen Antworten aus?

            bydey

            1. Du möchtest also mein falsches Ergebnis mit o.a. XSL-Datei sehen? Na gut! Hier ist es (Ausschnitt):

              ...
              Q3 POL DISCUSSION - CONVINCE FRIENDSWhen you hold a strong opinion, do you ever find yourself persuading your friends, relatives or fellow workers to share your views? Does this happen ...? (READ OUT)Last trend: EB47.0 Q.3 1. Often
              2. From time to time
              3. Rarely
              4. Never
              5. DK
              0. NA
              .
              .
              Q4A VALUE ORIENTATION - POL GOALS 1STThere is a lot of talk these days about what (OUR COUNTRY)'s goals should be for the next ten or fifteen years. On this card are listed some of the goals that different people say should be given top priority. Would you please say which one of them you, yourself, consider to be most important in the long run? (SHOW CARD - ONE ANSWER ONLY)Last trend: EB42.0 Q.3 1. Maintaining order in the country
              2. Giving the people more say in important government decisions
              3. Fighting rising prices
              4. Protecting freedom of speech
              5. DK
              0. NA
              .
              .
              Q4B VALUE ORIENTATION - POL GOALS 2ND[The country's most important goals]And what would be your second choice?See Q.4a for complete question text 1. Maintaining order in the country
              2. Giving the people more say in important government decisions
              3. Fighting rising prices
              4. Protecting freedom of speech
              5. DK
              0. NA
              .
              .
              Q5A TELEVISION USE - NEWSAbout how often do you ... (SHOW CARD)Last trend: EB46.0 Q.5 1. Everyday
              2. Several times a week
              3. Once or twice a week
              4. Less often
              5. Never
              6. DK
              0. NA
              .
              .
              Q5B DAILY NEWSPAPERS USE - NEWSAbout how often do you read the news in daily papers?See Q.5 for complete question text 1. Everyday
              2. Several times a week
              3. Once or twice a week
              4. Less often
              5. Never
              6. DK
              0. NA
              .
              ...
              Birgit

              HI.
              Jetzt häng mir einfach ein Stück vom falschen Ergebnis mit dran!

              bydey

              <?xml version="1.0" encoding="ISO-8859-1"?>
              <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

              <xsl:template match="dataDscr">
                 <html>
                    <body>
                       <h1>Tabelle Variable 38</h1>
                       <table border="1">
                          <tr>
                             <td>(Wert)</td><td>(Antwort)</td>
                          </tr>
                          <xsl:apply-templates select="var" />
                       </table>
                    </body>
                 </html>
              </xsl:template>

              <xsl:template match="catgry">
                 <tr>
                    <td><xsl:apply-templates select="catValu" />xsl:text.</xsl:text></td>

              <td><xsl:apply-templates select="txt" /></td>
                 </tr>
              </xsl:template>
              </xsl:stylesheet>

              Hilft Dir das weiter ohne komplette XML-Datei?

              Birgit

              Ok.

              1. Often
              2. Form time to time
                etc. )s.o.

              Wie sehen Deine falschen Antworten aus?

              bydey

              1. Du möchtest also mein falsches Ergebnis mit o.a. XSL-Datei sehen? Na gut! Hier ist es (Ausschnitt):

                ...
                Q3 POL DISCUSSION - CONVINCE FRIENDSWhen you hold a strong opinion, do you ever find yourself persuading your friends, relatives or fellow workers to share your views? Does this happen ...? (READ OUT)Last trend: EB47.0 Q.3 1. Often
                2. From time to time
                3. Rarely
                4. Never
                5. DK
                0. NA
                .

                Wieviele oder welche von den 1. 2. 3. codes möchtest Du in diesem Falle sehen?

                bydey

                1. Ich möchte alle Antworten von 1 bis 0, also genau in folgender Form:

                  1. Often
                  2. From time to time
                  3. Rarely
                  4. Never
                  5. DK
                  0. NA

                  Birgit

                  Du möchtest also mein falsches Ergebnis mit o.a. XSL-Datei sehen? Na gut! Hier ist es (Ausschnitt):

                  ...
                  Q3 POL DISCUSSION - CONVINCE FRIENDSWhen you hold a strong opinion, do you ever find yourself persuading your friends, relatives or fellow workers to share your views? Does this happen ...? (READ OUT)Last trend: EB47.0 Q.3 1. Often
                  2. From time to time
                  3. Rarely
                  4. Never
                  5. DK
                  0. NA
                  .

                  Wieviele oder welche von den 1. 2. 3. codes möchtest Du in diesem Falle sehen?

                  bydey

                  1. Hallo,

                    du steuerst ja auch ein Template an, dass es in Deinem Stylesheet nicht gibt. Ersetze die Zeile (im Template für das Wurzelelement):

                    <xsl:apply-templates select="var"/>

                    <xsl:apply-templates select="catgry"/>

                    und alles wird gut ;-)

                    Gruß
                    Franz

                    1. hallo Franz,

                      du steuerst ja auch ein Template an, dass es in Deinem Stylesheet nicht gibt. Ersetze die Zeile (im Template für das Wurzelelement):

                      <xsl:apply-templates select="var"/>

                      <xsl:apply-templates select="catgry"/>

                      und alles wird gut ;-)

                      *hüstel* wird nicht.
                      sie muss dort entweder <xsl:apply-templates /> angeben oder konkret so machen:

                      <?xml version="1.0" encoding="ISO-8859-1"?>
                      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

                      <xsl:template match="dataDscr">
                         <html>
                            <body>
                               <h1>Tabelle Variable 38</h1>
                               <table border="1">
                                  <tr>
                                     <td>(Wert)</td><td>(Antwort)</td>
                                  </tr>
                                  <xsl:apply-templates select="var"/>
                               </table>
                            </body>
                         </html>
                      </xsl:template>

                      <xsl:template match="var">
                         <xsl:apply-templates select="catgry"/>
                      </xsl:template>

                      <xsl:template match="catgry">
                         <tr>
                            <td><xsl:apply-templates select="catValu" />xsl:text.</xsl:text></td>

                      <td><xsl:apply-templates select="txt" /></td>
                         </tr>
                      </xsl:template>
                      </xsl:stylesheet>

                      grüße
                      thomas

                      1. Hallo Thomas,

                        *hüstel* wird nicht.

                        *hust*, *hust* ;-)

                        sie muss dort entweder <xsl:apply-templates /> angeben oder konkret so machen:

                        Ja, wenn *mehrere* Variablen verarbeitet werden sollen, hast du natürlich recht (dann sollte man wahrscheinlich auch die Tabellenstruktur in das Template für "var" verlegen). Ansonsten kann man natürlich jede beliebige EXISTIERENDE Template Rule ansteuern.

                        <xsl:template match="var">
                          <h1>Tabelle Variable 38</h1>
                                 <table border="1">
                                    <tr>
                                       <td>(Wert)</td><td>(Antwort)</td>
                                    </tr>
                          <xsl:apply-templates select="catgry"/>
                          </table>
                        </xsl:template>

                        Viele Grüße
                        Franz

                2. Sorry,
                  ich muß mich leider verabschieden.
                  Schade, dass ich nicht weiter helfen konnte.

                  bydey