0

I want to do this using xslt, new to this and struggling.

<xsl:template match="h1"> 
<h1 title=""> 
<xsl:apply-templates select="@* | node()"/> 
</h1> 
</xsl:template>

Example XML

<h1>This is the inner text <para>some other text</para>
</h1>

Desired output

  <h1 title="This is the inner text"><para>some other text</para>
</h1>
3
  • Where is the XSLT you have so far? Commented Nov 20, 2019 at 17:21
  • <xsl:template match="h1"> <h1 title=""> <xsl:apply-templates select="@* | node()"/> </h1> </xsl:template> Commented Nov 20, 2019 at 17:34
  • 2
    Please add that to your question. Commented Nov 20, 2019 at 17:36

1 Answer 1

1

I believe the following should work. You can remove your template for h1 as it would be superfluous:

<xsl:template match="h1/node()[1][self::text()]">
  <xsl:attribute name="title">
    <xsl:value-of select="." />
  </xsl:attribute>
</xsl:template>

This template matches a text node when it is the first child node of an h1, and substitutes it with a title attribute whose value is that of the text node.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.