Xml XSLT条件查找表

Xml XSLT条件查找表,xml,xslt,Xml,Xslt,我的XSLT中有两个查找表 表A: <manufacturerA:lookup> <device code="129" mapped="foo device"/> </manufacturerA:lookup> 预期结果 如果我转换源XML <blob> <protocol>1</protocol> <device> <type>129</type> </d

我的XSLT中有两个查找表

表A:

<manufacturerA:lookup>
  <device code="129" mapped="foo device"/>
</manufacturerA:lookup>
预期结果

如果我转换源XML

<blob>
  <protocol>1</protocol>
  <device>
    <type>129</type>
  </device>
</blob>
<blob>
  <protocol>2</protocol>
  <device>
    <type>129</type>
  </device>
</blob>
应分别转换为foo设备和bar设备

注:


源XML来自一个客户,因此,出于这个问题的目的,它的格式被刻在石头上。

使用。

我将我的作为参数,而不是硬编码查找表。考虑以下事项:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="no" />
<xsl:param name="tablename">xxxx</xsl:param>
<xsl:variable name="lookupDoc" select="document($tablename)" />

<xsl:template match="/">
    <test>
        <value><xsl:value-of select="$lookupDoc/root/tag1/etc/etc/etc"/></value>
    </test>
</xsl:template>

</xsl:stylesheet>

请记住,您的查找表都应该具有相同的模式。

您真漂亮!我不认为这很简单,但比我的努力要简单得多。谢谢。唉,我无法使用你的解决方案。这个条件赋值结构在Qt4中不受支持,所以我求助于使用两个查找变量和一个choose。。。当我的xsl:value of使用哪一个时。尽管如此,这仍然是一个很好的答案。我的表和模板位于一个单一的XSLT文档中,原因很简单,源XML可以有混合协议。这并不意味着你的答案是错的,只是意味着你的答案对我的问题不起作用。
<blob>
  <protocol>1</protocol>
  <device>
    <type>129</type>
  </device>
</blob>
<blob>
  <protocol>2</protocol>
  <device>
    <type>129</type>
  </device>
</blob>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="no" />
<xsl:param name="tablename">xxxx</xsl:param>
<xsl:variable name="lookupDoc" select="document($tablename)" />

<xsl:template match="/">
    <test>
        <value><xsl:value-of select="$lookupDoc/root/tag1/etc/etc/etc"/></value>
    </test>
</xsl:template>

</xsl:stylesheet>
xsltproc --stringparam tablename file2.xml tableparam.xsl 1639089.xml