Question

I have source like

  <h1> ...  <h1>  

(h1 may be h2 and h3 too.) h1 MAY have an id attribute. If it does NOT have an "id" attribute, I want to give it one. How would the template look, to match an h1 WITHOUT and attribute "id", and how would I process the tag then? Maybe like this?:

   <xsl:template match="(h1 | h2 | h3)[not(@id)]" >
   <!-- here I have to generate a tag h1, h2 or h3: how? -->
   <xsl:attribute name="id">G10.2</xsl:attribute>
   </h123>
   </xsl:template>
Was it helpful?

Solution

How about:

<xsl:template match="h1[not(@id)] | h2[not(@id)] | h3[not(@id)]" >
    <xsl:copy>
           <xsl:attribute name="id">G10.2</xsl:attribute>
           <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top