다음을 통해 공유


<xsl:attribute>의 예제 2

이 예제에서는 특성 값 템플릿을 사용하여 XML 소스 문서의 내용을 특성 이름으로 사용하는 방법을 보여 줍니다.

XML 파일(attribute.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="attribute.xsl"?>
<investment>
   <type>stock</type>
   <name>Microsoft</name>
   <price type="high">100</price>
   <price type="low">94</price>
</investment>

XSLT 파일(attribute.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes"/>

<xsl:template match="investment">
   <xsl:element name="{type}">
      <xsl:attribute name="name" >
         <xsl:value-of select="name"/>
      </xsl:attribute>
      <xsl:for-each select="price">
      <xsl:attribute name="{@type}" >
         <xsl:value-of select="."/>
      </xsl:attribute>
      </xsl:for-each>
   </xsl:element>
</xsl:template>
</xsl:stylesheet>

출력

형식이 지정된 출력이 없습니다. 다음은 프로세서 출력입니다.

<?xml version="1.0"?>

<stock name="Microsoft" high="100" low="94">

</stock>