Announcement

Collapse
No announcement yet.

Wie Inline Element Auswählen

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

  • Wie Inline Element Auswählen

    Hallo!

    Ich habe ein XML Dokument, welches Elemente enthält, die einerseits als Block Elemente aber auch als Inline Elemente auftreten können. Diese Elemente möchte ich bei der XSLT Transformation unterschiedlich behandeln. Wie selektiere ich das Element, wenn es als Inline Element auftritt?

    Beispiel für das Ausgangsdokument:

    Code:
    <para>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</para>
    
    <!-- hier ist mediaobject ein Block-Element-->
    <para>
    <mediaobject>
    <imageobject>
    <imagedata fileref="./images/block.png"  width="100%"/>
    </imageobject>
    <caption>
    <para>Block Image</para>
    </caption>
    </mediaobject>
    </para>
    
    <!-- hier ist mediaobject ein Inline-Element-->
    <para>
    Lorem ipsum (<mediaobject>
    <imageobject>
    <imagedata fileref="./images/icon.png"  width="100%"/>
    </imageobject>
    </mediaobject>) dolor sit amet,
    consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
    labore et dolore magna aliquyam erat, sed diam voluptua.
    </para>
    So soll das Ergebnisdokument aussehen:

    Code:
    <para>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</para>
    
    <figure>
        <title>some title</title>
        <mediaobject>
            <imageobject>
                <imagedata width="100%" fileref="./images/block.png"/>
            </imageobject>
        </mediaobject>
    </figure>
    
    <para>Lorem ipsum (<inlinemediaobject><imageobject><imagedata fileref="./images/icon.png" align="left" contentdepth="1em"/></imageobject></inlinemediaobject>) dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</para>
    Mein XSLT:

    Code:
    <!-- mediaobject ist Block Element -->
    <xsl:template match="mediaobject">
    
    .... transformation in figure ....
    
    </xsl:template>
     
    <!-- mediaobject ist Inline Element -->
    <xsl:template match="????">
    
    .... transformation in inlinemediaobject ....
    
    </xsl:template>
    Nochmal gefragt, wie selektiere ich das mediaobject Element wenn es innerhalb des para auftaucht UND von Text umgeben ist? Blöderweise ist das mediaboject als Block ebenfalls Kind-Element eines para, ich kann es deshalb nicht einfach per select="para/mediaobject" auswählen.

    Danke für eure Hilfe, nE

  • #2
    Mit
    Code:
    <xsl:template match="mediaobject[preceding-sibling::node()[1][self::text()[normalize-space()]] | following-sibling::node()[1][self::text()[normalize-space()]]">
      <!-- inline element as it is preceded by and/or followed by a non whitespace text node -->
    </xsl:template>
    
    <xsl:template match="mediaobject[not(preceding-sibling::node()[1][self::text()[normalize-space()]] | following-sibling::node()[1][self::text()[normalize-space()])]">
      <!-- block element as it is not preceded by and/or followed by a non whitespace text node -->
    </xsl:template>
    sollte es funktionieren.

    Comment


    • #3
      Danke! Das trifft die Sache ganz gut.

      VG, nE

      Comment

      Working...
      X