0

嗨,谢谢你

鉴于此输入 XML

<root>
<part id='74'>
    <title>Belt</title>
    <description>1158J5</description>
    <partno>C00112576</partno>
    <price>10.99</price>
</part>
<category id='6' name='Washer-Dryer'></category>
<category id='2' name='Washing machine'></category>
<make id='6' name='Ariston'></make>
<make id='2' name='Hotpoint'></make>
<make id='33' name='Indesit'></make>
<model catid='2' catname='Washing machine' makeid='6' makename='Ariston' modelid='524'>A1235</model>
<model catid='2' catname='Washing machine' makeid='2' makename='Hotpoint' modelid='413'>SCR37P</model>
<model catid='2' catname='Washing machine' makeid='2' makename='Hotpoint' modelid='35751'>WD440</model>
<model catid='6' catname='Washer-Dryer' makeid='33' makename='Indesit' modelid='2989'>WF000G</model>

我想将其转换为

<root>
<part id='74'>
    <title>Belt</title>
    <description>1158J5</description>
    <partno>C00112576</partno>
    <price>10.99</price>
</part>
<category id='6' name='Washer-Dryer'>
    <make id='33' name='Indesit'>
        <model catid='6' catname='Washer-Dryer' makeid='33' makename='Indesit' modelid='2989'>WF000G</model>
    </make>
</category>
<category id='2' name='Washing machine'>
    <make id='6' name='Ariston'>
        <model catid='2' catname='Washing machine' makeid='6' makename='Ariston' modelid='524'>A1235</model>
    </make>
    <make id='2' name='Hotpoint'>
        <model catid='2' catname='Washing machine' makeid='2' makename='Hotpoint' modelid='413'>SCR37P</model>
        <model catid='2' catname='Washing machine' makeid='2' makename='Hotpoint' modelid='35751'>WD440</model>
    </make>
</category>

我从 asp 经典提要中收到此 XML,我可以访问 asp 并且可以在那里执行,一旦收到我在 php 中,然后我发送到 xsl 转换以输出到浏览器

所以我的问题是哪一个是最好的方式,即 asp、php 或 xsl,是否有可能至少让我开始以最好的方式做到这一点

再次感谢蒂姆·道奇森

4

1 回答 1

0

谷歌搜索和拔头发的好日子,我想出了这个

<xsl:template match="root">
    <xsl:for-each select="//make">
        <xsl:variable name="makeid" select="@id" />
        <xsl:variable name="makename" select="@name" />
        <make id="{$makeid}" name="{$makename}">
        <xsl:for-each select="//model[@makeid = $makeid]">
            <model catid="{@catid}" catname="{@catname}" makeid="{@makeid}" makename="{@makename}" modelid="{@modelid}">
                <xsl:value-of select="."/>
            </model>
        </xsl:for-each>
        </make>
    </xsl:for-each> 
</xsl:template>

我知道它一开始并不完全是我想要的,但它可以满足我的需要。只是希望有人能说我是否至少朝着正确的方向前进

非常感谢蒂姆

于 2012-07-18T22:11:44.613 回答