XSLT翻译问题匹配子字符串文本



我正在寻找我试图创建的XSLT的一些帮助-我试图工作的问题是,如果attributeId包含子字符串"fault_code",我想获得AttributeAssignment的值:

输入:

 <AttributeAssignment AttributeId="att_obl_authorization_rule_fault_code" DataType="string" Issuer="" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment">ERROR</At‌​tributeAssignment> 

XSLT Ive tried:

<xsl:template match="AttributeAssignment">
  <xsl:if test="contains=('{@AttributeId}', 'fault_code')" > 
    <faultcode> soapenv:<xsl:value-of select='.'/> 
    </faultcode> 
     </xsl:if> 
</xsl:template> 

This:

<xsl:if test="contains=('{@AttributeId}', 'fault_code')" >

无效。

<xsl:if test="contains(@AttributeId, 'fault_code')" >

要测试,当这个XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="AttributeAssignment">
    <xsl:if test="contains(@AttributeId, 'fault_code')">
      <faultcode>soapenv:<xsl:value-of select="."/></faultcode>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

…或者这个更简单、更可扩展的XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="AttributeAssignment[contains(@AttributeId, 'fault_code')]">
    <faultcode>
      <xsl:value-of select="concat('soapenv:', .)"/>
    </faultcode>
  </xsl:template>
</xsl:stylesheet>

…*

<AttributeAssignment AttributeId="att_obl_authorization_rule_fault_code" DataType="string" Issuer="" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment">ERROR</AttributeAssignment>

…生成所需的结果:

<faultcode>soapenv:ERROR</faultcode>

最新更新