2013-10-20 2 views
0

XSLT를 사용하여 DocBook 파일의 최상위 <book> 노드에 xml:id=foo 속성을 추가하고 싶습니다. 뭔가 효과가 있습니다 만, 이것을 구현하는 간단한 방법이 있는지 궁금합니다.XSLT : 최상위 노드에 xml : id 속성 추가

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' 
       xmlns:db='http://docbook.org/ns/docbook' 
       version='1.0'> 

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

<xsl:template match="db:book"> 
    <xsl:copy> 
     <xsl:attribute name="xml:id"> 
      <xsl:text>foo</xsl:text> 
     </xsl:attribute> 
      <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

답변

1

당신은

<xsl:attribute name="xml:id"> 
     <xsl:text>foo</xsl:text> 
    </xsl:attribute> 

접근 방식이 좋은 것을보다

<xsl:attribute name="xml:id">foo</xsl:attribute> 

그러나 다른 단축 할 수 있습니다 : 여기에 내 현재의 솔루션입니다. 그리고 귀하의 버전은 가독성을 위해 선호 될 수 있습니다.