【发布时间】:2015-07-26 03:42:15
【问题描述】:
我刚刚开始学习 XLS,只需在下面修改我的 XML。特别是,我想复制<description> 元素的值并将其替换为其父<game> 的name 属性。
源 XML:
<?xml version="1.0"?>
<menu>
<game name="$100000P" index="" image="">
<description>$100,000 Pyramid (1988)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Box Office, Inc.</manufacturer>
<year>1988</year>
<genre>Strategy</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
<game name="$takes" index="" image="">
<description>High Stakes by Dick Francis (1986)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Mindscape, Inc.</manufacturer>
<year>1986</year>
<genre>Adventure</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
<game name="007Licen" index="" image="">
<description>007 - Licence to Kill (1989)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Domark Ltd.</manufacturer>
<year>1989</year>
<genre>Driving</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
...
期望的输出:
<?xml version="1.0"?>
<menu>
<game name="$100,000 Pyramid (1988)" index="" image="">
<description>$100,000 Pyramid (1988)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Box Office, Inc.</manufacturer>
<year>1988</year>
<genre>Strategy</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
<game name="High Stakes by Dick Francis (1986)" index="" image="">
<description>High Stakes by Dick Francis (1986)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Mindscape, Inc.</manufacturer>
<year>1986</year>
<genre>Adventure</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
<game name="007 - Licence to Kill (1989)" index="" image="">
<description>007 - Licence to Kill (1989)</description>
<cloneof></cloneof>
<crc></crc>
<manufacturer>Domark Ltd.</manufacturer>
<year>1989</year>
<genre>Driving</genre>
<rating></rating>
<enabled>Yes</enabled>
</game>
我尝试了以下 XSL,但它似乎没有做出任何改变。现在真的让我头疼。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="game">
<game name="{description}">
<xsl:apply-templates select="@*|node()"/>
</game>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
标签: xslt attributes parent-child elements