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>
문제
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>
해결책
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>