简体   繁体   English

在xslt版本1.0中匹配属性名称

[英]Match attribute name in xslt version 1.0

I have this XML file 我有这个XML档案

<REFERENCES>
    <COMPLETE REFERENCE="ABC1" />
    <CODIGO_SIM REFERENCE="ABC1" />
    <ETAPA REFERENCE="C1" />
    <NPP_SERIE REFERENCE="NAOBI" />
    <SIM_MPLD REFERENCE="METALIC" />
    <SIM_COCI REFERENCE="NOTTE" />
    <SIM_ANCH REFERENCE="563" />
    <NP_TIPO REFERENCE="Placard" />
</REFERENCES>

I want to filer only those entries starting with SIM_, but I couldn't, so I've modified the file adding the name of the attribute to its value, like this: 我只想提交以SIM_开头的那些条目,但是不能,所以我修改了文件,将属性名称添加到其值中,如下所示:

<REFERENCES>
    <COMPLETE REFERENCE="ABC1" />
    <CODIGO_SIM REFERENCE="ABC1" />
    <ETAPA REFERENCE="C1" />
    <NPP_SERIE REFERENCE="NAOBI" />
    <SIM_MPLD REFERENCE="SIM_MPLD|METALIC" />
    <SIM_COCI REFERENCE="SIM_COCCI|NOTTE" />
    <SIM_ANCH REFERENCE="SIM_ANCH|563" />
    <NP_TIPO REFERENCE="Placard" />
</REFERENCES>

and so I can filter those entries with this: 所以我可以用以下过滤这些条目:

<xsl:variable name="CodigoSim" select="REFERENCES/CODIGO_SIM/@REFERENCE" />
    <xsl:for-each select="REFERENCES//.//@REFERENCE" >
        <xsl:if test="starts-with(., 'SIM_')" >
            <xsl:value-of select="$CodigoSim"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select=" substring-after(., 'SIM_')" />
            <xsl:value-of select="substring-after(., '|')" />
            <xsl:call-template name="QuebrarLinha"/>
       </xsl:if>
     </xsl:for-each>

which does exactly what I want. 正是我想要的。 Is there anyway to obtain the same behaviour without changing the XML file? 无论如何,在不更改XML文件的情况下是否可以获得相同的行为?

If you need to select elements using some rule related to element's name then you can use something like this: 如果您需要使用一些与元素名称相关的规则来选择元素,则可以使用以下方法:

<xsl:for-each select="REFERENCES/*[starts-with(local-name(), 'SIM_')]">
  <xsl:value-of select="$CodigoSim"/>
  ...
</xsl:for-each>

local-name() is the part element's name that comes after namespace (if any), ie SIM_MPLD and etc. local-name()是名称元素(如果有)之后的部分元素名称,即SIM_MPLD等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM