我正在使用 XSLT 和 XML。
首先我要处理两个 xml。
第一个 XML:
<?xml version="1.0"?>
<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:232-83752-2" Managed="10682">
<tcm:Item ID="tcm:232-564598" Title="010 News Mapping"/>
<tcm:Item ID="tcm:232-564599" Title="020 CUGOs"/>
<tcm:Item ID="tcm:232-614307" Title="030 Reserved Urls"/>
</tcm:ListItems>
我们将使用上面的 ID 获取第二个 XML,即 tcm:232-564598 等,下面是 ID tcm:232-564598 的 xml 之一,其他 ID 将具有相同类型的 XML。
<tcm:Component ID="tcm:229-564598" IsEditable="false" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<tcm:Data>
<tcm:Content>
<MappingCollection xmlns="uuid:922EEC29-2DE3-4BA1-A46A-A300CB8FA85F">
<VanityUrl>
<old>mbp</old>
<new>/SessionHandler.aspx?pageurl=/BP.aspx&pub=/english&section=IBE&j=f</new>
<dateAdded>2010-05-03T14:45:00</dateAdded>
<comments> News mapping </comments>
</VanityUrl>
<VanityUrl>
<old>about/news</old>
<new>about/news/news.aspx</new>
<dateAdded>2010-05-03T14:45:00</dateAdded>
<comments> News mapping </comments>
</VanityUrl>
</MappingCollection>
</tcm:Content>
</tcm:Data>
</tcm:Component>
我试图使用以上两个 XML 来获得以下格式的 XML。
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<!-- News mapping -->
<mapping old="mbp" new="/SessionHandler.aspx?pageurl=/BP.aspx&pub=/english&section=IBE&j=f"/>
<mapping old="about/news" new="about/news/news.aspx"/>
<!-- CUGO's-->
<mapping old="/nhs" new="/cugo.aspx?promoCode=UKNHS01&pub=/uk/english"/>
<mapping old="/hk/ukstudentfare" new="/cugo.aspx?promoCode=HKSTU10&pub=/hk/Chinese"/>
</mappings>
这是我的 XSLT,我试图在其中生成上述格式的 XML,但它对我不起作用。请注意第一个 xml 是主要的 xml,它将使用下面的 XSLT 进行转换
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:em="http://www.espire.com/tridion/schemas" xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant" exclude-result-prefixes="em xlink tcmse tcm">
<xsl:output method="xml" version="1.0" encoding="UTF-16" indent="yes"/>
<!-- root match-->
<xsl:template match="tcm:ListItems">
<mappings>
<xsl:apply-templates select="tcm:Item"/>
</mappings>
</xsl:template>
<xsl:template match="tcm:Item">
<xsl:variable name="doc" select="document(@ID)"/>
<xsl:if test="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:comments">
<xsl:comment>
<xsl:value-of select="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:comments"/>
</xsl:comment>
</xsl:if>
<xsl:for-each select="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl">
<xsl:element name="mapping">
<xsl:if test="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:old">
<xsl:attribute name="old">
<xsl:value-of select="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:old"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:new">
<xsl:attribute name="new">
<xsl:value-of select="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:new"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:dateAdded">
<xsl:attribute name="dateAdded">
<xsl:value-of select="$doc/tcm:Component/tcm:Data/tcm:Content/em:MappingCollection/em:VanityUrl/em:dateAdded"/>
</xsl:attribute>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
在上面的 xslt 中,我能够得到数据循环也正确,但即将到来的数据是相同的,我的意思是循环执行正确,但节点值是相同的
请建议!