>

이 XML을 변형 시키길 원한다고

<?xml version="1.0" encoding="UTF-8"?>
<package id="album">
    <concept id="tracknumber" value="18"></concept>
    <concept id="songtitle" value="Multi Love"></concept>
    <concept id="band" value="Unknown Mortal Orchestra"></concept>
</package>

이 XML로 :

<package>
    <tracknumber>18</tracknumber>
    <songtitle>Multi Love</songtitle>
    <band>Unknown Mortal Orchestra</band>
</package>

이것은 소스 XML을 변환하는 시작점 XSLT입니다.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
        <xsl:template match="package[@id='album']">
            <package>
                <tracknumber>
                    <xsl:value-of select="concept[@id='tracknumber']" />
                </tracknumber>
                <songtitle>
                    <xsl:value-of select="concept[@id='songtitle']" />
                </songtitle>
                <band>
                    <xsl:value-of select="concept[@id='band']" />
                </band>
            </package>
        </xsl:template>
    </xsl:stylesheet>

XML 속성의 "값"부분을 얻는 것이 까다로운 것 같습니다.


  • 답변 # 1

    XML에 많은 <concept> 가 포함 된 경우 명시적인 값 기준없이 동적 XSLT 솔루션을 고려하십시오.  태그 :

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
        <xsl:template match="package[@id='album']">
            <xsl:copy>
                <xsl:apply-templates select="concept" />
            </xsl:copy>
        </xsl:template>
        <xsl:template match="concept">            
            <xsl:element name="{@id}">
                <xsl:value-of select="@value" />
            </xsl:element>            
        </xsl:template>
    </xsl:stylesheet>
    
    

  • 답변 # 2

    사용할 XSLT입니다 :

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="package[@id='album']">
        <package>
            <tracknumber>
                <xsl:value-of select="concept[@id='tracknumber']/@value />
            </tracknumber>
            <songtitle>
                <xsl:value-of select="concept[@id='songtitle']/@value" />
            </songtitle>
            <band>
                <xsl:value-of select="concept[@id='band']/@value" />
            </band>
        </package>
       </xsl:template>
    </xsl:stylesheet>
    
    

  • 이전 c# - Visual Studio에서 디버깅 할 때 기본 연결이 닫혔습니다 오류
  • 다음 javascript - 왜 React 아코디언 애니메이션이 작동하지 않습니까?