Announcement

Collapse
No announcement yet.

alles zwischen zwei tags herausextrahieren???

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

  • alles zwischen zwei tags herausextrahieren???

    Hallo ich habe ein Problem. Kann mir jemand weiterhelfen?

    <root>
    <page>
    <text left="79" top="1371" width="877" height="46">10</text>
    <text left="79" top="1375" width="877" height="46">a</text>
    <text left="79" top="1421" width="781" height="46">b</text>
    <text left="79" top="1468" width="720" height="46">c</text>
    <text left="79" top="1500" width="872" height="46">20</text>
    <text left="79" top="1516" width="872" height="46">a</text>
    <text left="79" top="1521" width="877" height="46">a</text>
    <text left="79" top="1570" width="877" height="46">a</text>
    <text left="79" top="1600" width="872" height="46">30</text>
    <text left="79" top="1602" width="877" height="46">a</text>
    <text left="79" top="1670" width="877" height="46">b</text>
    </page>
    <page>
    <text left="79" top="1375" width="877" height="46">c</text>
    <text left="79" top="1421" width="781" height="46">d</text>
    <text left="79" top="1468" width="720" height="46">e</text>
    <text left="79" top="1500" width="872" height="46">40</text>
    <text left="79" top="1516" width="872" height="46">a</text>
    <text left="79" top="1521" width="877" height="46">a</text>
    <text left="79" top="1570" width="877" height="46">a</text>
    </page>
    </root>

    Also wenn man sich das anschaut sieht man dass da zahlen gibt von 10 bis 50
    ich möchte als ergebnis alles haben was dazwischen ist:

    <root>
    <page>
    <x>
    <text left="79" top="1371" width="877" height="46">10</text>
    <text left="79" top="1375" width="877" height="46">a</text>
    <text left="79" top="1421" width="781" height="46">b</text>
    <text left="79" top="1468" width="720" height="46">c</text>
    </x>
    <x>
    <text left="79" top="1500" width="872" height="46">20</text>
    <text left="79" top="1516" width="872" height="46">a</text>
    <text left="79" top="1521" width="877" height="46">a</text>
    <text left="79" top="1570" width="877" height="46">a</text>
    </x>
    <x>
    <text left="79" top="1600" width="872" height="46">30</text>
    <text left="79" top="1602" width="877" height="46">a</text>
    <text left="79" top="1670" width="877" height="46">b</text>
    </x>
    </page>
    <page>
    <x>
    <text left="79" top="1375" width="877" height="46">c</text>
    <text left="79" top="1421" width="781" height="46">d</text>
    <text left="79" top="1468" width="720" height="46">e</text>
    </x>
    <x>
    <text left="79" top="1500" width="872" height="46">40</text>
    <text left="79" top="1516" width="872" height="46">a</text>
    <text left="79" top="1521" width="877" height="46">a</text>
    <text left="79" top="1570" width="877" height="46">a</text>
    </x>
    </page>

    also man könnte die @tops nehmen dann following bis zum nächsten top?
    wie geht das?
    kann mir jemand weiterhelfen?
    also ganz allgemein würde mir auch helfen.

    Danke und viele Grüße,
    Tamer

  • #2
    Probiere diesen Ansatz:
    Code:
    <xsl:template match="root">
      <root>
        <xsl:apply-templates select="page"/>
      </root>
    </xsl:template>
    
    <xsl:template match="page">
      <page>
        <xsl:for-each select="text[1] | text[number(.) mod 10 = 0]">
          <xsl:variable name="c1" select="count(following-sibling::text)"/>
          <xsl:variable name="c2" select="count(following-sibling::text[number(.) mod 10 = 0]/following-sibling::text)"/>
          <xsl:variable name="anz">
            <xsl:choose>
              <xsl:when test="$c2 = 0">
                <xsl:value-of select="$c1 - $c2"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$c1 - $c2 - 1"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <x>
            <xsl:copy-of select="."/>
            <xsl:for-each select="following-sibling::text[position() &lt;= $anz]">
              <xsl:copy-of select="."/>
            </xsl:for-each>
          </x>
        </xsl:for-each>
      </page>
    </xsl:template>

    Comment


    • #3
      Danke aber ich depp wollte eigentlich was anders :-( :-(

      Problem xslt 1.0

      Ich habe eine XML-Datei die Tabellen repräsentiert

      Code:
      A B C D
      x x x x
      ---------
      x x x x
      
      A B C D
      x
      --------
      x x    x
      
      A B C D
      x x x x
      x
      --------
      Die Linie ----- repräsentiert eine Zeile. Ich möchte die Zeilen von den Tabellen gruppieren.


      Die XML-Datei schaut so aus:
      Code:
      <printjob>
      <page number="1">
             <TAX_ITEM>
                 <text left="234" top="2678" width="125" height="46">1373.00</text>
                 <text left="526" top="2678" width="57" height="46">2.4</text>
                 <text left="738" top="2678" width="80" height="46">81.96</text>
                 <text left="1007" top="2678" width="125" height="46">1381.96</text>
                 <text left="234" top="2737" width="125" height="46">dies ist ein</text>
                 <text left="526" top="2737" width="57" height="46">7.6</text>
                 <text left="738" top="2737" width="80" height="46">8.21</text>
                 <text left="1007" top="2737" width="125" height="46">116.21</text>
             </TAX_ITEM>
      </page>
      <page number="2">
             <TAX_ITEM>
                 <text left="234" top="2678" width="125" height="46">test</text>
                 <text left="234" top="2737" width="125" height="46">1108.00</text>
                 <text left="526" top="2737" width="57" height="46">7.6</text>
                 <text left="1007" top="2737" width="125" height="46">116.21</text>
             </TAX_ITEM>
      </page>
      <page number="3">
             <TAX_ITEM>
                 <text left="234" top="2678" width="125" height="46">dies ist ein</text>
                 <text left="526" top="2678" width="57" height="46">2.4</text>
                 <text left="738" top="2678" width="80" height="46">81.96</text>
                 <text left="1007" top="2678" width="125" height="46">1381.96</text>
                 <text left="234" top="2778" width="125" height="46">test</text>
             </TAX_ITEM>
      </page>
      </printjob>
      Was ich gerne haben will:

      Code:
      <printjob>
      <page number="1">
             <TAX_ITEM>
                 <line>
                 <text left="234" top="2678" width="125" height="46">1373.00</text>
                 <text left="526" top="2678" width="57" height="46">2.4</text>
                 <text left="738" top="2678" width="80" height="46">81.96</text>
                 <text left="1007" top="2678" width="125" height="46">1381.96</text>
                 </line>
                 <line>
                 <text left="234" top="2737" width="125" height="46">dies ist ein  test</text>
                 <text left="526" top="2737" width="57" height="46">7.6</text>
                 <text left="738" top="2737" width="80" height="46">8.21</text>
                 <text left="1007" top="2737" width="125" height="46">116.21</text>
                 </line>
             </TAX_ITEM>
      </page>
      <page number="2">
             <TAX_ITEM>
                 <line>
                 <text left="234" top="2737" width="125" height="46">1108.00</text>
                 <text left="526" top="2737" width="57" height="46">7.6</text>
                 <text left="1007" top="2737" width="125" height="46">116.21</text>
                 </line>
             </TAX_ITEM>
      </page>
      <page number="3">
             <TAX_ITEM>
                 <line>
                 <text left="234" top="2678" width="125" height="46">dies ist ein  test</text>
                 <text left="526" top="2678" width="57" height="46">2.4</text>
                 <text left="738" top="2678" width="80" height="46">81.96</text>
                 <text left="1007" top="2678" width="125" height="46">1381.96</text>
                 <line>
             </TAX_ITEM>
      </page>
      </printjob>
      Was ich weiß:

      1. Die Elemente in der Spalte B sind Pflichtfelder (2.4, 7.6, 2.4, 2.4, 7.6). Diese signalisieren eine neue Zeile. Falls es kein solches Element gibt, dann heißt das, dass es zur oberen Zeilenspalte gehört und muss konkateniert werden.

      2. Ich weiß die Abstände der Tabellenspalten durch die leftpositionen für
      a von 75 bis 364, b von 356 bis 586, c von 578 bis 821 und d von 813 bis 1134

      Was ich jetzt ewig probiere und schaffen will:

      1. Hole dir alle top elemente von der Spalte B.
      2. Hole dir alles was zwischen dem 1. und dem 2. ist ist. das zweite ausgeschlossen natürlich. Dann vom 3. bis 4. usw.
      3. Falls eine neue Page anfängt und es kein Pflichtelement in Spalte b gibt, dann konkateniere es mit dem Wert der Zeile davor aus der vorherigen Seite.

      Das wäre super nett, falls das jemand lösen könnte.
      Tamer
      Zuletzt editiert von Tamer; 30.11.2009, 17:56.

      Comment

      Working...
      X