3

UPDATED CODE:

    <?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>

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.

thanks for looking!

EDIT #2:

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 Input here

XSL Output is below:

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

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.

thanks for everybodys time

Docjay
  • 123
  • 3
  • 14

3 Answers3

6

You can use translate function.

<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, ' ,', '^^')"/>
Lingamurthy CS
  • 5,412
  • 2
  • 13
  • 21
  • I tried your first example and the output didn't change, so I guess the 'space' wasn't caught by the test? – Docjay Mar 12 '14 at 19:07
  • You don't need xsl:choose, here at all.. use this: – Lingamurthy CS Mar 12 '14 at 19:08
  • also, as suggested by @deanosaur, please correct the XSLT.. it isn't well formed. – Lingamurthy CS Mar 12 '14 at 19:10
  • 1
    @Docjay Are you sure those are space characters you have in there - and not some other white space characters, such as non-breaking space, for example? – michael.hor257k Mar 12 '14 at 19:17
  • I'm not certain, I'm sure they were created with a press of the space-bar by users. – Docjay Mar 12 '14 at 19:28
  • @Docjay Then most likely you are doing something wrong. That's the problem with partial information. Post an example of your XML document and add your **current** stylesheet (i.e. the one using the above suggestion). – michael.hor257k Mar 12 '14 at 19:35
  • I have removed the 'xsl:choose' and it still does not catch the space in the $PatName. Maybe they are not space characters. – Docjay Mar 12 '14 at 19:36
  • Can you edit your question with your input XML and used XSLT? – Lingamurthy CS Mar 12 '14 at 19:38
  • @Docjay You could have 99 other problems in your stylesheet. They are not going to be detected by reading your description of it. Show us the code. Including the XML. – michael.hor257k Mar 12 '14 at 19:38
  • I have no XML - sorry all I use for the software we have are .xsl stylesheets and the transformer does the rest in JBOSS. I have updated the code above with the stylesheet. I'm sorry it was incomplete. – Docjay Mar 12 '14 at 19:40
  • @Docjay Do you know how to apply the identity transform to your input? If you do, please do so and post the result here (it will be an exact copy of your input). – michael.hor257k Mar 12 '14 at 19:49
  • No, I have never done that, but I search around for examples and do my best to apply it to '$PatName'. – Docjay Mar 12 '14 at 19:59
0

This is not an answer, but I need to post some code.

Please apply the following stylesheet to your (original) input and report the results:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="patName" select="/dataset/attr[@tag='00100010']" />

<xsl:template match="/">
    <tests>
        <value><xsl:value-of select="$patName" /></value>
        <contains><xsl:value-of select="contains($patName, '&#32;')" /></contains>
        <trans><xsl:value-of select="translate($patName, '&#32;' , '^')" /></trans>
    </tests>
</xsl:template>

</xsl:stylesheet> 
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • I used your stylesheet above and applied it to my original input. Here is the input [link](http://www.pastebin.ca/2658482) & Here is the output: -sorry for the formatting. – Docjay Mar 13 '14 at 14:19
  • @Docjay That's not possible. You cannot get this result using my stylesheet, on any input. – michael.hor257k Mar 13 '14 at 14:30
  • I'm very sorry - that must only be what was coerced on output (which was nothing). I'm trying to figure out how to look in JBOSS 4.2.3 where the exact out is from the transformer. Thanks a lot for all of your patience and help on this & please don't give me too many eye rolls! LOL – Docjay Mar 13 '14 at 15:12
0

change

<xsl:param name="PatName" select="attr[@tag='00100010']"/>

into

<xsl:param name="PatName" select="dataset/attr[@tag='00100010']"/>

and change

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

into

<xsl:value-of select="translate($PatName, ' ,','^^')"/>
Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14