0

以下のxmlテキストがあります。

<SUBSCRIBER>
    <Anumber>639081000000</Anumber>
    <FirstCallDate>20130430104419</FirstCallDate>
    <SetyCode>TNT</SetyCode>
    <Status>ACT</Status>
    <RoamIndicator/>
    <PreloadCode>P1</PreloadCode>
    <CreationDate>20130116100037</CreationDate>
    <PreActiveEndDate/>
    <ActiveEndDate>20130804210541</ActiveEndDate>
    <GraceEndDate>20140502210541</GraceEndDate>
    <RetailerIndicator/>
    <OnPeakAccountID>9100</OnPeakAccountID>
    <OnPeakSmsExpDate>20130804210504</OnPeakSmsExpDate>
    <UnivWalletAcc/>
    <UnliSmsOnCtl>20130606211359</UnliSmsOnCtl>
    <UnliSmsTriCtl/>
    <UnliSmsGblCtl/>
    <UnliMocOnCtl>20130606211359</UnliMocOnCtl>
    <UnliMocTriCtl/>
    <UnliMocGblCtl/>
    <UnliSurfFbcCtl>20130606212353</UnliSurfFbcCtl>
</SUBSCRIBER>

各xmlタグ名を反復/解析して値を取得するにはどうすればよいですか(タグの名前と別の変数の値が必要です)? また、特定のタグ名から反復を開始するにはどうすればよいですか? 例: UnivWalletAcc の繰り返しを開始したい

お知らせ下さい。

これまでのところ、私は次のことを試しました、

<xsl:template match="SUBSCRIBER">
    <xsl:variable name="tagName">
        <xsl:value-of select="/*/*/name()"/>
    </xsl:variable>
    <xsl:variable name="tagValue">
        <xsl:value-of select="/*/*/text()"/>
    </xsl:variable>
    <xsl:value-of select="$tagName"/>
    <xsl:value-of select="$tagValue"/>
</xsl:template>
4

2 に答える 2

3

Veenstra のソリューションの代わりに、SUBSCRIBER/* テンプレートの xsl:if の代わりに、apply-templates で繰り返しを制御できます。

<xsl:template match="SUBSCRIBER">
    <data>
        <xsl:apply-templates select="UnivWalletAcc, 
                                     UnivWalletAcc/following-sibling::*" />
    </data>
</xsl:template>
于 2013-10-28T17:06:25.007 に答える
1

次の XSLT を使用すると、ノード SUBSCRIBER のすべての子ノードをループできます。

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

    <!-- Identity template that will loop over all nodes and attributes -->
    <xsl:template match="@*|node()">
        <xsl:apply-templates select="@*|node()" />
    </xsl:template>

    <!-- Template to match the root and create new root -->
    <xsl:template match="SUBSCRIBER">
        <data>
            <xsl:apply-templates select="@*|node()" />
        </data>
    </xsl:template>

    <!-- Template to loop over all childs of SUBSCRIBER node -->
    <xsl:template match="SUBSCRIBER/*">
        <!-- This will test if we have seen the UnivWalletAcc node already, if so, output something, otherwise, output nothing -->
        <xsl:if test="preceding-sibling::UnivWalletAcc or self::UnivWalletAcc">
            <tag>
                <tagName><xsl:value-of select="name()" /></tagName>
                <tagValue><xsl:value-of select="." /></tagValue>
            </tag>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
于 2013-10-28T15:23:04.477 に答える