문제

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top