0

从中<xsl:value-of select="$CashFlowAttach" />将出现包含数据的 XML 代码,我需要从该值中提取文件名 {例如:值可能是<p xmlns:Utils="cim:Utils"><a href="resources/Attachment/spend plan.123"><image border="0" width="89px" height="47px" src="resources/Content/images/CIMtrek_spend_plan_123.gif"></image></a></p>} 我需要值是文件名 = 最后花费计划.123。任何条件都可以在 XSL 表单中进行检查

<xsl:choose>
 <xsl:when test="string-length($CashFlowAttach)!=0">
  <xsl:if test="not(contains($CashFlowAttach,'&lt;p xmlns:Utils=&quot;cim:Utils&quot;&gt;'))">
   <a>
    <xsl:attribute name="onclick">ajaxcallingForFileDownload('<xsl:value-of        select="$CashFlowAttach" />')  
    </xsl:attribute>
     <xsl:value-of select="$CashFlowAttach" />
   </a>
  </xsl:if>
 </xsl:when>
</xsl:choose>
4

1 回答 1

2

我建议将此模板添加到您的 XSLT:

  <xsl:template name="GetFileName">
    <xsl:param name="path" />
    <xsl:choose>
      <xsl:when test="contains($path, '/')">
        <xsl:call-template name="GetFileName">
          <xsl:with-param name="path"
                          select="substring-after($path, '/')" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$path"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

此模板可用于获取路径末尾的文件名。然后你会用这样的东西来调用它:

<xsl:variable name="fileName">
  <xsl:call-template name="GetFileName">
     <xsl:with-param name="path"
      select="substring-before(substring-after($CashFlowAttach, 'a href=&quot;'), 
                                  '&quot;')" />
  </xsl:call-template>
</xsl:variable>
于 2013-02-04T10:09:22.447 回答