Avatar of badtz7229
badtz7229Flag for United States of America

asked on 

XSL: replacing empty space with known value

I have the following xml input

sample 1:
<root>      
      <SeatElementNumber>1</SeatElementNumber>
      <CommandRS>
            <Response>MI&lt;X&gt;TKT NBR&lt;             &gt;</Response>
      </CommandRS>
      <Create>...       </Create>
</root>

sample 2:
<root>      
      <SeatElementNumber>1</SeatElementNumber>
      <CommandRS>
            <Response>MI&lt;X&gt;TKT NBR&lt;1234&gt;</Response>
      </CommandRS>
      <Create>...       </Create>
</root>

      

I currently have code which will extract the values between the lt and gt in order to build a Request xml as follows:
      <CommandRQ><Request><X><1234></Request></CommandRQ>

However, if the the TKT NBR in the input is null (like in sample 1), i want to use the tktNumber i stored in a prior variable. How can i do this in xsl?
This is code I have so far.

    <xsl:key  name="TktMatch"  match="View/Identify/Info[TicketNumber/@Status='TICKETED']/SegmentElementNumber"   use="." />      
    <xsl:variable name="SeatSegment" select="/root/Create/Other/Seat[position() = 1]/SegmentIDRef"/>    
    <xsl:variable name="TktNumber" select="key('TktMatch', $SeatSegment)/@TicketNumber"/>
       
    <xsl:template match="CommandRS">
            <xsl:apply-templates/>
        </CommandRQ>
    </xsl:template>
          
    <xsl:template match="Response">
        <Request>
            <xsl:call-template name="strip-between-tags">
                <xsl:with-param name="str" select="."/>
            </xsl:call-template>
        </Request>
    </xsl:template>

    <xsl:template name="strip-between-tags">
        <xsl:param name="str"/>
        <xsl:choose>
            <xsl:when test="contains($str, '&lt;')">
                <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
                <xsl:value-of select="substring-before(substring-after($str, '&lt;'), '&gt;')"></xsl:value-of>
                <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
                <xsl:call-template name="strip-between-tags">
                    <xsl:with-param name="str" select="substring-after($str, '&gt;')"/>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
CSSXML

Avatar of undefined
Last Comment
Gertone (Geert Bormans)
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of badtz7229
badtz7229
Flag of United States of America image

ASKER

Gertone,
your code worked (thanks) but when I execute the xsl (using Visual Studios) it seems to be returning the values that are in the <Create> node

The reponse builds as follows

   <CommandRQ><Request><X><1234></Request></CommandRQ>
                  2
                        
                              1
                              82D
                        
                  
                  
                        
                              1
                              2
                              RA
                              
                                    SRT
                                    SEAT
                              
                              
                              Pre-reserved Seating
                              82D
well, that is standard processing,
All I changed was the named template and calling it,

This is a context processing issue that must have been there before
(I could not see full context of XSLT nor source XML)

There are a number of things you can do

If you never need to process the create, add an empty template for it
<xsl:template match="Create"/>

Or process the request from a higher level

instead of

<xsl:template match="Response">
        <Request>
            <xsl:call-template name="strip-between-tags">
                <xsl:with-param name="str" select="."/>
                <xsl:with-param name="deep" select="1"/>
            </xsl:call-template>
        </Request>
    </xsl:template>

do

<xsl:template match="CommandRS">
        <Request>
            <xsl:call-template name="strip-between-tags">
                <xsl:with-param name="str" select="Response"/>
                <xsl:with-param name="deep" select="1"/>
            </xsl:call-template>
        </Request>
    </xsl:template>
Avatar of badtz7229
badtz7229
Flag of United States of America image

ASKER

I have
      
    <xsl:template match="CommandRS">
        <CommandRQ>
            <xsl:apply-templates/>
        </CommandRQ>
    </xsl:template>
      
    <xsl:template match="Response">
        <Request>
            <xsl:call-template name="strip-between-tags">
                <xsl:with-param name="str" select="."/>
              <xsl:with-param name="deep" select="1"/>
            </xsl:call-template>
        </Request>
    </xsl:template>      
      
      
      
    <xsl:template name="strip-between-tags">
        <xsl:param name="str"/>
        <xsl:param name="deep"/>
            .....
    </xsl:template>
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of badtz7229
badtz7229
Flag of United States of America image

ASKER

I do need <Create> in order to get $TktNumber and i processed at a higher level, but it still shows all data from the <Create>
Avatar of badtz7229
badtz7229
Flag of United States of America image

ASKER

<xsl:template match="Create"/>
<xsl:template match="SeatElementNumber"/>

that worked.
but why is it necessary to include that, i dont' understand?
Please send me the full XSLT you have and a full XML source
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of badtz7229
badtz7229
Flag of United States of America image

ASKER

Thanks for ur help and explanation
welcome
CSS
CSS

Cascading Style Sheets (CSS) is a language used for describing the look and formatting of a document written in a markup language. Usually used to change web pages and user interfaces written in HTML, it can also be applied to any kind of XML document. CSS is designed primarily to distinguish the content of a document from its presentation.

43K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo