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

  • Thread starter Le TeXnicien de Surface
  • Start date
L

Le TeXnicien de Surface

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
 
M

Martin Honnen

Le said:
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>
 
J

Joseph Kesselman

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top