当两个元素在xslt中具有相同的名称时,如何将它们链接在一起?
我有这些树,一棵是这种结构/汽车/汽车,另一棵是制造商/汽车/汽车。第一个列表引用了第二个汽车列表的id当两个元素在xslt中具有相同的名称时,如何将它们链接在一起?,xslt,Xslt,我有这些树,一棵是这种结构/汽车/汽车,另一棵是制造商/汽车/汽车。第一个列表引用了第二个汽车列表的id <xsl:template match="t:cars/t:car"> <tr> <td> <xsl:if test="position()=1"> <b><xsl:value-of select="../@name"/><xsl:text> </xsl:
<xsl:template match="t:cars/t:car">
<tr>
<td>
<xsl:if test="position()=1">
<b><xsl:value-of select="../@name"/><xsl:text> </xsl:text></b>
</xsl:if>
</td>
</tr>
我有这个,它充满了一个for循环,我在一点之后才知道我做不到
这是以前的情况:
<xsl:template match="t:cars/t:car">
<tr>
<td>
<xsl:if test="position()=1">
<b><xsl:value-of select="../@name"/><xsl:text> </xsl:text></b>
</xsl:if>
<xsl:for-each select="/t:root/t:maker/t:car">
<xsl:if test="t:root/t:maker/@id = @ref">
<xsl:value-of select="@title"/>
</xsl:if>
</xsl:for-each>
</td>
</tr>
样本:
auto>
<maker type="toyota">
<car name="prius" id="1"/>
</maker>
<cars name="My Collection">
<car ref="1" />
</cars>
auto>
这个简单的转换:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kCarById" match="maker/car" use="@id"/>
<xsl:template match="/*">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="cars/car">
<tr>
<td>
<b>
<xsl:value-of select="key('kCarById', @ref)/@name"/>
</b>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<table>
<tr>
<td>
<b>accord</b>
</td>
</tr>
<tr>
<td>
<b>mercedes</b>
</td>
</tr>
</table>
当应用于此XML文档时(提供的文档只扩展了一点):
这个简单的转换:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kCarById" match="maker/car" use="@id"/>
<xsl:template match="/*">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="cars/car">
<tr>
<td>
<b>
<xsl:value-of select="key('kCarById', @ref)/@name"/>
</b>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<table>
<tr>
<td>
<b>accord</b>
</td>
</tr>
<tr>
<td>
<b>mercedes</b>
</td>
</tr>
</table>
当应用于此XML文档时(提供的文档只扩展了一点):
示例输入和必需的输出xml将使您更容易理解问题示例输入和必需的输出xml将使您更容易理解问题