我有这个XML(简略)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="uncle.xsl"?>
<report>
<title>Bibliography</title>
<dateCreated>2016-07-21T10:33:22</dateCreated>
<dateFormat>yyyy/mm/dd</dateFormat>
<catalog>
<marc>
<marcEntry tag="245" label="Title" ind="00">Title 1</marcEntry>
</marc>
<call>
<callNumber>Call_1_VALLA</callNumber>
<item>
<itemID>item_1_VALLA</itemID>
</item>
</call>
<call>
<callNumber>Call_2_VALLA</callNumber>
<item>
<itemID>item_2_VALLA</itemID>
</item>
<item>
<itemID>item_2_2_VALLA</itemID>
</item>
</call>
<call>
<callNumber>Call_3_CNB</callNumber>
<item>
<itemID>item_3_CNB</itemID>
</item>
</call>
</catalog>
<catalog>
<marc>
<marcEntry tag="245" label="Title" ind="04">Title 2</marcEntry>
</marc>
<call>
<callNumber>Call_4_VALLA</callNumber>
<item>
<itemID>item_4-VALLA</itemID>
</item>
</call>
<call>
<callNumber>Call_5_CNB</callNumber>
<item>
<itemID>item_5_CNB</itemID>
</item>
<item>
<itemID>item_5_2_CNB</itemID>
</item>
</call>
</catalog>
</report>
我想将每个itemID与最接近的前一个“叔叔”(callNumber)结合起来,因此得到如下列表:Title 1 Call_1_VALLA item_1_VALLA
标题1通话_2_VALLA item_2_VALLA
标题1通话_2_VALLA item_2_2_VALLA
标题1通话_3_CNB项_3_CNB
标题2通话_4_VALLA item_4-VALLA
标题2通话_5_CNB项目_5_CNB
标题2通话_5_CNB项目_5_2_CNB
我创建了一个样式表-但是,它选择了第一个叔叔而不是最近的叔叔。
标题1通话_1_VALLA项目_1_VALLA
标题1通话_1_VALLA item_2_VALLA
标题1通话_1_VALLA item_2_2_VALLA
标题1通话_1_VALLA item_3_CNB
标题2通话_4_VALLA item_4-VALLA
标题2通话_4_VALLA项_5_CNB
标题2通话_4_VALLA item_5_2_CNB
这些是我的样式表的相关部分-需要改进什么?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<catalog>
<xsl:for-each select="report/catalog/call/item">
<itemline>
<Title><xsl:value-of select="../../marc/marcEntry[@tag='245']"/></Title>
<callNumber><xsl:value-of select="../../call/callNumber"/></callNumber>
<itemID><xsl:value-of select="itemID"/></itemID>
</itemline>
</xsl:for-each>
</catalog>
</xsl:template>
</xsl:stylesheet>
您需要将的输出更改callNumber
为此...
<callNumber><xsl:value-of select="../callNumber"/></callNumber>
也许这
<callNumber><xsl:value-of select="preceding-sibling::callNumber"/></callNumber>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句