我有这个 XML 片段:
<svrl:successful-report test="."
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][1]/*[local-name()='section']">
我想获取值@location
并删除特殊字符" *[local-name()=' "
和" '] "
. 换句话说,我希望输出是
/ClinicalDocument/component/structuredBody/component[1]/section
我目前正在使用这个字符串替换模板:
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text"
select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
并像这样应用模板
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@location"/>
<xsl:with-param name="replace" select="'[local-name()='"/>
<xsl:with-param name="by" select="''"/>
</xsl:call-template>
这只给出了这个结果:
/*'ClinicalDocument']/*'component']/*'structuredBody']/*'component'][1]/*'section']
我怎样才能得到我想要的输出?