2013-06-04 1 views
2

모든 속성과 요소가있는 요소의 사본을 내부의 하위에 출력해야합니다. 주요 문제는 속성을 알 수 없다는 것입니다.XSLT : 요소 사본 내에 템플릿을 적용하십시오.

XML :

<elem attrA="a" attrB="b" ... attrN="n"> 
    <child><child> 
    <child><child> 
</elem> 

나는 모든 속성을 통해 루프를 시도하지만,이 작업을 얻을 수 없습니다.

<xsl:template match="elem"> 
    <xsl:element name="name(.)"> 
    <xsl:for-each select="@*"> 
     <xsl:attribute name="name()"> 
     <xsl:value-of select="."/> 
     </xsl:attribute> 
    </xsl:for-each> 
    <xsl:apply-templates /> 
    </xsl:element> 
</xsl:template> 

필수 출력 :

<elem attrA="a" attrB="b" ...="" attrN="n"> 
    <processed-child></processed-child> 
    <processed-child></processed-child> 
</elem> 

지정된 아이 템플릿 :

<xsl:template match="child"> 
    <processed-child><xsl:value-of select="."/></processed-child> 
</xsl:template> 

편집 :

XSLT 1.0

+0

* * "이 작업을 얻을 수 없다"설명해주십시오 :

완벽한 솔루션 (그것은 원래의 게시물에 설명하지만, 요구 사항이었다되지 않았다). – Tomalak

+0

@Tomalak, 오류가 발생합니다 : '('문자, 16 진수 값 0x28은 이름에 포함될 수 없습니다 .. –

+0

'

답변

3

012을합니까
<xsl:template match="elem"> 
    <xsl:copy> 
    <xsl:copy-of select="@*" /> 
    <xsl:apply-templates select="*" /> 
    </xsl:copy> 
</xsl:template> 

작동하지 않습니까?

+0

정말 간단합니다 .. 감사합니다! –

1

Tomalak의 답을 추가하기 만하면 최종 솔루션이 향상되어 태그 주변에서 텍스트 렌더링이 가능해졌습니다.

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

<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>