如何在 XSLT 1.0 中进行代码表查找 [英] How to do a code table lookup in XSLT 1.0

查看:18
本文介绍了如何在 XSLT 1.0 中进行代码表查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 XSLT 1.0 版中的代码表进行查找?我试着做这样的例子:https://www.xml.com/pub/a/2002/02/06/key-lookups.html,但我认为在这种情况下数据在输入文件中而不是在 XSLT 本身中.

How can I do a lookup from a code table in XSLT version 1.0? I tried to do something like this example: https://www.xml.com/pub/a/2002/02/06/key-lookups.html, but I think in that case the data was in the input file and not in the XSLT itself.

我创建了一个名为lookup"的命名空间并尝试了以下操作,其中我在 XSLT 代码中查找表,但我总是得到空值.我是否需要将其移动到应用模板结构?

I created a namespace called "lookup" and tried the following, where my lookup table in the XSLT code itself, but I always get empty values. Do I need to move this to an apply-template structure?

<lookup:TenderActionType>
    <string id='00'>Add</string>
    <string id='01'>Cancel</string>
    <string id='04'>Update</string>
    <string id='05'>Update</string>
    <string id='56'>Cancel</string>
    <string id='06'>Add</string>
    <string id='46'>Cancel</string>
</lookup:TenderActionType>
<xsl:key name='tenderActionType' match='string' use='@id' />
<!-- I tried this as well --> 
<xsl:key name='tenderActionType2' match='lookup:TenderActionTypestring' use='@id' />

以下代码用于使用 Microsoft BizTalk 转换为 XML 的 EDI 文件.

Code below is in a working for an EDI file converted to XML with Microsoft BizTalk.

      <ChangeStatus>
        <xsl:value-of select="key('tenderActionType', s0:B2A/B2A01/text())" />
      </ChangeStatus>
      <ChangeStatusTest>
        <xsl:value-of select="key('tenderActionType', '04')"/>            
      </ChangeStatusTest>

推荐答案

基于此 post,我让它工作了.还引用了 post 以正确传递参数.

Based on this post, I got it working. Also referenced post to pass the parameter correctly.

因为我在使用 Microsoft,所以我不得不将 exsl 更改为 msxsl.我放弃了使用钥匙的想法.

As I was using Microsoft, I had to change exsl to msxsl. I dropped the idea of using the key.

<xsl:variable name="LookupTenderActionType">
    <string id='00'>Add</string>
    <string id='01'>Cancel</string>
    <string id='04'>Update</string>
    <string id='05'>Update</string>
    <string id='56'>Cancel</string>
    <string id='06'>Add</string>
    <string id='46'>Cancel</string>
</xsl:variable>
<xsl:variable name="lookupSet" select="msxsl:node-set($LookupTenderActionType)" />

我同时使用文字和 XPATH 值进行测试,直到我知道我的 XPATH 是正确的:

I was testing both with a literal and an XPATH value, until I knew my XPATH was correct:

       <Process> 
          <ChangeStatus>
            <xsl:call-template name="PerformLookupTenderActionType">
               <xsl:with-param name="lookupNumericCode" select="s0:B2A/B2A01/text()"/>
            </xsl:call-template>              
          </ChangeStatus>
          <ChangeStatusTest>
            <xsl:call-template name="PerformLookupTenderActionType">
               <xsl:with-param name="lookupNumericCode" select="04"/>
            </xsl:call-template>              
          </ChangeStatusTest>

模板充当查找子程序/函数:

The template acts as the lookup subroutine/function:

<xsl:template name="PerformLookupTenderActionType">
    <xsl:param name="lookupNumericCode"/>
    <xsl:value-of select="$lookupSet/string[@id = $lookupNumericCode]"/>
</xsl:template>

在 XML 输出中得到了我想要的结果(将 04 的代码转换为更新"):

Got my desired result in XML output (converted code of 04 to "Update"):

ChangeStatus>Update</ChangeStatus>

这篇关于如何在 XSLT 1.0 中进行代码表查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆