首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Schematron替换特殊字符?

如何用Schematron替换特殊字符?
EN

Stack Overflow用户
提问于 2015-10-13 11:13:54
回答 2查看 316关注 0票数 0

如何替换属性中的特殊字符和空格?我尝试过各种正则表达式,但没有一种是有兴趣的。

代码语言:javascript
复制
<pattern id="setElementId">
  <rule context="*[contains(@class, ' domain/element ') and boolean(@id)]">
    <!-- Works, replaces 'a' -->
    <let name="reqId" value="replace(@id, '[a]', '')"/>
    <assert test="@id=$reqId" sqf:fix="setId">
      The attribute "id" must comply with the given rules: "<value-of select="$reqId"/>" 
    </assert>
    <sqf:fix id="setId">
      <sqf:description>
       <sqf:title>Set "id" to "<value-of select="$reqId"/>"</sqf:title>
       <sqf:p>Set "id" to the calculated value.</sqf:p>
      </sqf:description>
      <sqf:replace match="@id" node-type="attribute" target="id" select="$reqId"/>
    </sqf:fix>
  </rule>
</pattern>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-14 07:53:01

我使用sergioFC建议的替换语句回答我自己的问题。

代码语言:javascript
复制
<pattern id="setElementId">
  <rule context="*[contains(@class, ' topic/dlentry ') and boolean(@id) and descendant-or-self::*[contains(@class, ' ui-d/uicontrol ')]]" role="info">
    <let name="reqId" value="descendant-or-self::*[contains(@class, ' ui-d/uicontrol ')]"/>
    <let name="reqId" value="replace($reqId, 'ä', 'ae')"/>
    <let name="reqId" value="replace($reqId, 'ö', 'oe')"/>
    <let name="reqId" value="replace($reqId, 'ü', 'ue')"/>
    <let name="reqId" value="replace($reqId, 'Ä', 'ue')"/>
    <let name="reqId" value="replace($reqId, 'Ö', 'ue')"/>
    <let name="reqId" value="replace($reqId, 'Ü', 'ue')"/>
    <let name="reqId" value="replace($reqId, 'ß', 'ss')"/>
    <let name="reqId" value="replace($reqId, '[^0-9a-zA-Z]', '')"/>
    <assert test="@id=$reqId" sqf:fix="setId" role="warning">
      The attribute "id" must comply with the given rules: "<value-of select="$reqId"/>" 
    </assert>
    <sqf:fix id="setId">
      <sqf:description>
       <sqf:title>Set "id" to "<value-of select="$reqId"/>"</sqf:title>
       <sqf:p>Set "id" to the calculated value.</sqf:p>
      </sqf:description>
      <sqf:replace match="@id" node-type="attribute" target="id" select="$reqId"/>
    </sqf:fix>
  </rule>
</pattern>

使用这种模式,我可以根据后代id元素的值为<dlentry>元素生成<uicontrol>属性。

票数 0
EN

Stack Overflow用户

发布于 2015-10-13 11:16:48

我想你最后的努力没有后悔。

检查CSS代码:

代码语言:javascript
复制
Style {template.css}

将其从最终用户的示例中删除,您将得到您的答案!

代码语言:javascript
复制
<sqf:replace match="@id" node-type="attribute" target="id" select="$reqId"/>
</sqf:fix>

它没有返回边值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33101194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档