Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String XSLT2.0:使用分析字符串过滤节点/文本,但还需要抓取XML标记_String_Xpath_Nodes_Xslt 2.0_Xmlspy - Fatal编程技术网

String XSLT2.0:使用分析字符串过滤节点/文本,但还需要抓取XML标记

String XSLT2.0:使用分析字符串过滤节点/文本,但还需要抓取XML标记,string,xpath,nodes,xslt-2.0,xmlspy,String,Xpath,Nodes,Xslt 2.0,Xmlspy,我正在完成我的第一个主要XSLT项目,我是一个新手,所以请耐心等待我的无知 我们的团队正在致力于将现有的XML转换为一个完全不同的标记系统。我已经设计了一个使用分析字符串处理MathType标注(由“${TEXT}”表示)的系统,但是我很难确定应该如何处理需要保存在结果代码中的ital标记(由“I”标记表示)之类的代码 我尝试在不匹配的子字符串中使用的副本,但似乎不起作用。当然,除ital标记外,的值可以获取所有内容 我意识到变量($stemString)在这一点上是多余的。我当时正沿着这条路走

我正在完成我的第一个主要XSLT项目,我是一个新手,所以请耐心等待我的无知

我们的团队正在致力于将现有的XML转换为一个完全不同的标记系统。我已经设计了一个使用分析字符串处理MathType标注(由“${TEXT}”表示)的系统,但是我很难确定应该如何处理需要保存在结果代码中的ital标记(由“I”标记表示)之类的代码

我尝试在不匹配的子字符串中使用的副本,但似乎不起作用。当然,除ital标记外,的值可以获取所有内容

我意识到变量($stemString)在这一点上是多余的。我当时正沿着这条路走,我想我可能会想出一些东西,让副本能够处理,但到目前为止,运气不好

示例代码:

<stem>What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}</stem>
<stem type="text">What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}, and ${##A112800eqn02:3} is 3.</stem>
当${##A112800eqn01:3}时,f(x)的值是多少
我当前的XSLT:

<?xml version="1.0" encoding="UTF-8"?>


错误

期望输出:

<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/>, and <img alt="##A112800eqn02" height="10" id="##A112800eqn02" label="" longdesc="normal" src="##A112800eqn02" width="10"/> is 3.</p>

我得到的是:

<p>What is the value of f(x) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01:3}, and ${##A112800eqn02" height="10" id="##A112800eqn01:3}, and ${##A112800eqn02" label="" longdesc="normal" src="##A112800eqn01:3}, and ${##A112800eqn02" width="10"/> is 3.</p>

有人对如何进行有什么想法吗

@马丁·霍宁:谢谢你的回复。你的代码解决了这个错误

不过,我还有一个问题。当阀杆中有多个MathType标注时,会导致错误。我确信原因是我的正则表达式没有正确地捕获所有内容,但我已经苦练了一段时间,但没有任何效果。下面我将说明我的问题

示例代码:

<stem>What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}</stem>
<stem type="text">What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}, and ${##A112800eqn02:3} is 3.</stem>
当${##A112800eqn01:3}和${##A112800eqn02:3}为3时,f(x)的值是多少。
期望输出:

<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/>, and <img alt="##A112800eqn02" height="10" id="##A112800eqn02" label="" longdesc="normal" src="##A112800eqn02" width="10"/> is 3.</p>
当f(x)的值是多少,并且是3

我得到的是:

<p>What is the value of f(x) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01:3}, and ${##A112800eqn02" height="10" id="##A112800eqn01:3}, and ${##A112800eqn02" label="" longdesc="normal" src="##A112800eqn01:3}, and ${##A112800eqn02" width="10"/> is 3.</p>
当f(x)为3时,它的值是多少


在元素上不匹配,然后将
xsl:choose
放在模板内部以进一步区分,而只是为不同的元素或具有特定属性值的元素编写模板

如果要使用
分析字符串
,请在
文本
节点的模板中执行,而不是在包含混合内容的元素的模板中:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="assessmentItem">

<!--SNIP-->

    <xsl:apply-templates select="stemArea/stem"/>

<!--SNIP-->

</xsl:template>

<xsl:template match="stem[. = '' and @type!='art'] | stem[. = ' ' and @type != 'art']"/>

<xsl:template match="stem[@style='box' or @style='boxL']">
  <p><span label="Tag_7"><xsl:apply-templates/></span></p>
</xsl:template>

<xsl:template match="stem[.//text()[matches(., '\$\{.+\}')]]">
  <p>
    <xsl:apply-templates/>
  </p>
</xsl:template>

<xsl:template match="stem//text()[matches(., '\$\{.+\}')]">
  <xsl:analyze-string regex="(\$\{{)(##.+[eqn|art]\d+)([^a-zA-Z0-9]?.*\}})" select=".">
    <xsl:matching-substring>
      <img alt="{regex-group(2)}" height="10" id="{regex-group(2)}" label="" longdesc="normal" src="{regex-group(2)}" width="10"/>
    </xsl:matching-substring>
    <xsl:non-matching-substring>
        <xsl:value-of select="."/>
    </xsl:non-matching-substring>
  </xsl:analyze-string>
</xsl:template>

</xsl:stylesheet>

这似乎是正确的轨道。我会做一些测试,今天给你回复。谢谢你的回复,谢谢你的代码。它工作得很好。我在上面补充了另一个问题,如果你能投入更多精力的话。你已经帮了我很多了。干杯本杰明,我添加了第二个代码示例,使用非贪婪匹配,希望能够满足您的精细需求。工作起来很有魅力。金星。非常感谢。Martin Honnen下面的代码可以很好地修复我的错误。