0

私は次のxmlファイルを持っています

<musicLibrary>
<compilation id="C01" title="Best of something">
    <title no="1" name="firstOne">
        <fileID>F01</fileID>
    </title>
    <title no="2" name="secondOne">
        <fileID>F02</fileID>
    </title>
    <title no="3" name="thirdOne">
        <fileID>F03</fileID>
    </title>
    <title no="4" name="fourthOne">
        <fileID>F04</fileID>
        <fileID>F05</fileID>
    </title>
</compiltion>
<compilation id="C02" title="Best of another thing">
    ...
</compilation>

<files>
    <file id="F01">
        <filename>soundFile8.mp3</filename>
        <size>3.456</size>
        <length>3.23</length>
    </file>
    <file id="F02">
        <filename>soundFile2.mp3</filename>
        <size>3.456</size>
        <length>3.23</length>
    </file>
    <file id="F03">
        <filename>soundFile7.mp3</filename>
        <size>3.456</size>
        <length>3.23</length>
    </file>
    <file id="F04">
        <filename>soundFile5.mp3</filename>
        <size>3.456</size>
        <length>3.23</length>
    </file>
    <file id="F05">
        <filename>soundFile3.mp3</filename>
        <size>3.456</size>
        <length>3.23</length>
    </file>
</files>
</musicLibrary>

コレクションIDを指定するだけで、ファイル情報から取得できますか?たとえば、1回のコンパイルの合計再生時間はどれくらいですか?私は本当にこれで立ち往生しています。:/SQLからの結合のようなものが本当に欠けています;)

前もって感謝します!

4

1 に答える 1

1

これは、xpathを使用してXSLTスタイルシートで実行できます(これは、XSLTの同等の結合と考えることができます)。このスタイルシートでは、各コンパイルの長さの合計が返されます。

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

    <xsl:template match="musicLibrary">
        <xsl:apply-templates select="compilation"/>  
    </xsl:template>

    <xsl:template match="compilation">
        <xsl:variable name="ids" select="title/fileID"/>
        <compilation id="{@id}" title="{@title}">
            <xsl:attribute name="total-length"> 
                <xsl:value-of select="sum(//files/file[@id = $ids]/length)"/>
            </xsl:attribute>
        </compilation>
    </xsl:template>

</xsl:stylesheet>

出力:

<compilation id="C01" title="Best of something" total-length="16.15"/>
于 2013-01-04T22:18:07.743 に答える