XSL 用插入符号替换空格 [英] XSL replace space with caret

查看:60
本文介绍了XSL 用插入符号替换空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新代码:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="no"/>
  <!-- overwritten by application with actual values -->
  <xsl:param name="calling" select="'SAMPLE_MOD'"/>
  <xsl:param name="called" select="'SERVER1'"/>
  <xsl:param name="date" select="'20051206'"/>
  <xsl:param name="time" select="'115600.000'"/>
  <xsl:param name="PatName" select="attr[@tag='00100010']"/>
  <xsl:template match="/dataset">
     <dataset>
     <xsl:variable name="PerfProcStepDesc" select="attr[@tag='00400254']"/>
     <xsl:variable name="StudyDesc" select="attr[@tag='00081030']"/>
       <xsl:if test="string-length($StudyDesc)=0">
         <xsl:if test="$PerfProcStepDesc">
            <!-- (0008,1030) Study Description -->
           <attr tag="00081030" vr="LO">
             <xsl:value-of select="$PerfProcStepDesc"/>
           </attr>
         </xsl:if>
       </xsl:if>
     </dataset>
     <dataset>
        <xsl:variable name="caret" select="'^'"/>
        <xsl:if test="contains($PatName, ' ')">
            <xsl:value-of select="translate($PatName, ' ','^')"/>
        </xsl:if>   
     </dataset>
  </xsl:template>
</xsl:stylesheet>

变量 'PatName' 可能会出现为 'DOE JOHN',我需要将它转换为 'DOE^JOHN' 名称中也可能有多个空格,所以我希望所有的 '空格' 都改为插入符号和保留他们当前在名称中的位置.

The variable 'PatName' could come across as 'DOE JOHN' and I need it be transformed to 'DOE^JOHN' There could also be multiple spaces in the name, so I would like all 'spaces' changed to carets and to keep their current place in the name.

我需要对名字中的逗号做同样的事情.

I need to do the same with commas that are in the name.

目前输出和输入一样,所以我的测试没有正常工作.

Currently the output coming out just as it went in, so my test is not working as it should.

感谢您的关注!

编辑#2:

我已经更改了我的代码以应用身份转换(希望我的代码是正确的!)此外,当它处理我的 XSL 样式表时,我还有 XSL 输入和 XSL 输出.

I have changed my code to apply a identity transform (hopefully I have it correct!) Also I have the XSL input and XSL output for when it processed my XSL stylesheet.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="no"/>
  <!-- overwritten by application with actual values -->
  <xsl:param name="calling" select="'SAMPLE_MOD'"/>
  <xsl:param name="called" select="'SERVER1'"/>
  <xsl:param name="date" select="'20051206'"/>
  <xsl:param name="time" select="'115600.000'"/>
  <xsl:param name="PatName" select="attr[@tag='00100010']"/>
<!-- IdentityTransform -->
<xsl:template match="/ | @* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
</xsl:template>
  <xsl:template match="/dataset">
     <dataset>
     <xsl:variable name="PerfProcStepDesc" select="attr[@tag='00400254']"/>
     <xsl:variable name="StudyDesc" select="attr[@tag='00081030']"/>
       <xsl:if test="string-length($StudyDesc)=0">
         <xsl:if test="$PerfProcStepDesc">
            <!-- (0008,1030) Study Description -->
           <attr tag="00081030" vr="LO">
             <xsl:value-of select="$PerfProcStepDesc"/>
           </attr>
         </xsl:if>
       </xsl:if>
     </dataset>
     <dataset>
        <xsl:variable name="caret" select="'^'"/>
        <xsl:if test="contains($PatName, ' ')">
            <xsl:value-of select="translate($PatName, ' ','^')"/>
        </xsl:if>   
     </dataset>
  </xsl:template>
</xsl:stylesheet>

XSL 输入 此处

XSL 输出如下:

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

在 XSL 输入中,患者姓名"有SMPTE PATTERN",我期待的是SMPTE^PATTERN".

in the XSL input, 'Patient Name' there is 'SMPTE PATTERN' and I am expecting 'SMPTE^PATTERN'.

我希望这会有所帮助,我希望我的身份转换器正确.

I hope this of some help and I hope I have the identity transformer correct.

感谢大家的时间

推荐答案

可以使用翻译功能.

<xsl:value-of select="translate($PatName, ' ', '^')"/>

如果您想用插入符号替换逗号和空格,请使用:

If you want to replace both comma and space with carets, use this:

<xsl:value-of select="translate($PatName, ' ,', '^^')"/>

这篇关于XSL 用插入符号替换空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆