我需要从itunes library.xml文件中提取曲目ID和位置。我找到了一些XSLT解决方案,但它们都是基于XSLT 2.0版的。
我只能使用XSLT 1.0版。
有没有人能帮我做到这一点。
输出应为:
98,location---
100,location 2非常感谢你的帮助,马蒂亚斯
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>Tracks</key>
<dict>
<key>98</key>
<dict>
<key>Track ID</key>
<integer>98</integer>
<key>Name</key>
<string>xxxxxx</string>
<key>Location</key>
<string>location---</string>
</dict>
<key>100</key>
<dict>
<key>Track ID</key>
<integer>100</integer>
<key>Name</key>
<string>name2</string>
<key>Location</key>
<string>location 2</string>
</dict>
</dict>
</dict>
</plist>发布于 2013-11-04 20:51:21
因此,对于曲目dict中的每个key,您需要提取Location。这样如何:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:apply-templates select="plist/dict/dict/key" />
</xsl:template>
<xsl:template match="key">
<xsl:value-of select="." />
<xsl:text>,</xsl:text>
<!-- find the dict corresponding to this key, and extract the value of
the Location entry -->
<xsl:value-of select="
following-sibling::dict[1]/key[. = 'Location']/following-sibling::string[1]" />
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>如果plist始终将Location作为最后一个条目,那么您可以简单地说
<xsl:value-of select="following-sibling::dict[1]/string[last()]" />但是,通过找到正确的键值,然后获取它的第一个后续string会更健壮。
https://stackoverflow.com/questions/19767922
复制相似问题