to copy the content of an element <p> inside a <note> but not outside

Discussion in 'XML' started by Le TeXnicien de Surface, Jan 24, 2008.

  1. hello

    I'm new to xslt and i'm trying to use it to go from a xml (tei4 compliant)
    to a html

    I've got <note></note> nested inside <p></p> and those <note> contain <p>
    and the like. I would like to obtain the content of the <p> nested inside
    the <note> but nothing if <p> is outside a <note>.

    That is to transform

    <p>Some text, I'm not interested in <note><p>This is my precious
    note</p></note> and still uninterresting things.</p>

    into just

    <div class="note"><p>This is my precious note</p></div>

    I would greatly appreciate any hint.

    Thank you very much

    --
    Le TeXnicien de Surface
     
    Le TeXnicien de Surface, Jan 24, 2008
    #1
    1. Advertising

  2. Re: to copy the content of an element <p> inside a <note> but notoutside

    Le TeXnicien de Surface wrote:

    > That is to transform
    >
    > <p>Some text, I'm not interested in <note><p>This is my precious
    > note</p></note> and still uninterresting things.</p>
    >
    > into just
    >
    > <div class="note"><p>This is my precious note</p></div>


    <xsl:template match="p[note[p]">
    <!-- or match="p[note]" might suffice -->
    <xsl:apply-templates select="note"/>
    </xsl:template>

    <xsl:template match="note">
    <div class="note">
    <xsl:apply-templates/>
    </div>
    </xsl:template>

    <xsl:template match="note/p">
    <xsl:copy>
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 24, 2008
    #2
    1. Advertising

  3. Re: to copy the content of an element <p> inside a <note> but notoutside

    Either check the p's ancestors, or have the template for the note
    element introduce and have separate templates for p's in general vs. p's
    in that mode.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 24, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    1
    Views:
    362
    darrel
    May 25, 2006
  2. Magnus Warker
    Replies:
    9
    Views:
    876
    Nigel Wade
    Apr 23, 2007
  3. Logan Lee
    Replies:
    11
    Views:
    451
    Philip Potter
    Dec 16, 2007
  4. Eric Sosman
    Replies:
    3
    Views:
    434
    Eric Sosman
    Nov 19, 2009
  5. Herbert Rosenau

    Re: calloc working inside the for loop but not outside

    Herbert Rosenau, Nov 23, 2009, in forum: C Programming
    Replies:
    5
    Views:
    485
    Keith Thompson
    Nov 25, 2009
Loading...

Share This Page