Announcement

Collapse
No announcement yet.

Kindknoten ansprechen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Kindknoten ansprechen

    Hallo,

    ich habe ein Problem mit

    Code:
    <wurzel>
     <table_structure>
      <field>...</field>
      ...
      <field>...</field>
     </table_structure>
     <weiter>
      <field>...</field>
       ...
       <field>...</field>
     </weiter>
    </wurzel>
    Code:
    <xsl:template match="table_structure">
     <xsl:for-each select="child::*">
       <xsl:if test="name()='field' ">
         <xsl:value-of select="name()"/>
       </xsl:if>
     </xsl:for-each>
    </xsl:template>
    und zwar möchte ich dies auf die Kindknoten des Knotens "table_structure" beschränken.
    Momentan nimmt er scheinbar alle Kindknoten des Wurzelknotens. Ich habe es schon folgendermassen probiert:

    <xsl:if test="name() = 'field' and ancestor[name() = 'table_structure']">

    d.h. ich möche nur alle "field" Knoten ansprechen, die auch "table_structure" als Vaterknoten haben. Nur funktioniert diese Abfrage scheinbar nicht, es muss wohl ein Fehler in dem Ausdruck vorliegen. Kann mir jemand bitte dabei behilflich sein?


    Vielen Dank für Antwort im voraus!

  • #2
    Unter Hinzunahme von
    Code:
    <xsl:template match="wurzel">
      <xsl:apply-templates select="table_structure"/>
    </xsl:template>
    kommt es zur gewünschten Ausgabe.

    Strukturierter ist dieser Ansatz:
    Code:
    <xsl:template match="wurzel">
      <xsl:apply-templates select="table_structure"/>
    </xsl:template>
    
    <xsl:template match="table_structure">
      <xsl:apply-templates select="field"/>
    </xsl:template>
    
    <xsl:template match="field">
      <xsl:value-of select="."/>
    </xsl:template>

    Comment

    Working...
    X