Solved

changing  one node  of xml based on the child node is partially working

Posted on 2015-01-25
11
96 Views
Last Modified: 2015-01-26
Hi,

Below is the xml, I am trying to change certain tags based on the child tags,
 
I am trying to change the tag <MA> to <MAP>  by checking  if the  
<xsl:if test="Approval/MAQualified/Person/Prescription !=''">which seem to work with the xslt ,
and I am also trying to change <MA> to <MAR>  if
<xsl:if test="Rejection/@type='STOP'"> which is not working , is there any work around this..? can the same tag <MA> cannot be tested twice..
Thanks in advance.  
 
 Here is my XML

<CNRBenefitsDetails>            
   <MA>
                                    <TitleLogo>.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Approval>
                                                <Title>Who qualifies</Title>
                                                <TitleLogo> eligible.gif</TitleLogo>
                                                <Header1>Who qualifies</Header1>
                                                <Header2>When</Header2>
                                                <Header3>Which package</Header3>
                                                <Header4>Prescriptions</Header4>
                                                <Header5>Access </Header5>
                                                <MAQualified>
                                                            <Person>
                                                                        <Name>\b.TON\b0.</Name>
                                                                        <When>Starting Dec 16, 2014</When>
                                                                        <Package>Child</Package>
                                                                        <Prescription> YES</Prescription>
                                                                        <AccessNo>39 </AccessNo>
                                                            </Person>
                                                </MAQualified>
                                                <Footer>Each family member eligible </Footer>
                                    </Approval>
                        </MA>
                       
                        <MA>
                                    <TitleLogo>.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Rejection type="STOP">
                                                <Title>Who does not qualify?</Title>
                                                <TitleLogo>gif</TitleLogo>
                                                <Header1>Who?</Header1>
                                                <Header2>Date of our decision?</Header2>
                                                <Description>
                                                            <Reason>
                                                                        <Value1>\b.TAM</Value1>
                                                                        <Value2>December </Value2>
                                                            </Reason>
                                                </Description>
                                                <Footer> TAM You do not qualify </Footer>
                                    </Rejection>
                        </MA>
            </CNRBenefitsDetails>

Open in new window


 below is the xslt i am trying to work with
 
 
 <xsl:stylesheet version="1.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="CNRBenefitsDetails/MA">
 <xsl:variable name="ename">
 <xsl:text>MA</xsl:text>
 <xsl:if test="Rejection/@type='STOP'">
 <xsl:text>R</xsl:text>
 </xsl:if>
</xsl:variable>
 <xsl:element name="{$ename}"> <xsl:copy-of select="@*"/>
 <xsl:apply-templates select="node()"/>
 </xsl:element>
 </xsl:template>
 
 
 <xsl:template match="CNRBenefitsDetails/MA">
 <xsl:variable name="ename">
 <xsl:text>MA</xsl:text>
 <xsl:if test="Approval/MAQualified/Person/Prescription !=''">
 <xsl:text>P</xsl:text>
 </xsl:if>
</xsl:variable>
 <xsl:element name="{$ename}"> <xsl:copy-of select="@*"/>
 <xsl:apply-templates select="node()"/>
 </xsl:element>
 </xsl:template>

Open in new window


removing the xslt code for either of the conditions works for other..
0
Comment
Question by:sri1209
  • 7
  • 4
11 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40569727
You have two templates that have an equal match attribute, meaning they are ambiguous
Most processor will raise a warning and pick the last... meaning that MAR will never happen
You will need to combine them into one
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40569728
<xsl:stylesheet version="1.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="CNRBenefitsDetails/MA">
        <xsl:variable name="ename">
            <xsl:text>MA</xsl:text>
            <xsl:if test="Rejection/@type='STOP'">
                <xsl:text>R</xsl:text>
            </xsl:if>
            <xsl:if test="Approval/MAQualified/Person/Prescription !=''">
                <xsl:text>P</xsl:text>
            </xsl:if>
        </xsl:variable>
        <xsl:element name="{$ename}"> <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40569733
I have two xsl:if in there assuming they are mutually exclusive
if not, you will need an xsl:choose
0
 

Author Comment

by:sri1209
ID: 40571157
Hi Geert Bormans,

Awesome, just one more scenario where i am not able to get a hold, i.e, there is one more tag in the xml with <MA> but under a different parentnode <Summary> , like the xml below, i am trying to get the <MA> tag under <Summary> to be <MAO> i have tried the solution you provided and that works great for the <MA> tags under <CNRBenefitsDetails>
when i tried doing the same  for <Summary> it does not get me the result, i am sure i am doing wrong but i am not sure how to do it.

<CNRBenefitsDetails>            
   <MA>
                                    <TitleLogo>.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Approval>
                                                <Title>Who qualifies</Title>
                                                <TitleLogo> eligible.gif</TitleLogo>
                                                <Header1>Who qualifies</Header1>
                                                <Header2>When</Header2>
                                                <Header3>Which package</Header3>
                                                <Header4>Prescriptions</Header4>
                                                <Header5>Access </Header5>
                                                <MAQualified>
                                                            <Person>
                                                                        <Name>\b.TON\b0.</Name>
                                                                        <When>Starting Dec 16, 2014</When>
                                                                        <Package>Child</Package>
                                                                        <Prescription> YES</Prescription>
                                                                        <AccessNo>39 </AccessNo>
                                                            </Person>
                                                </MAQualified>
                                                <Footer>Each family member eligible </Footer>
                                    </Approval>
                        </MA>
                       
                        <MA>
                                    <TitleLogo>.gif</TitleLogo>
                                    <Title> Benefits</Title>
                                    <Rejection type="STOP">
                                                <Title>Who does not qualify?</Title>
                                                <TitleLogo>gif</TitleLogo>
                                                <Header1>Who?</Header1>
                                                <Header2>Date of our decision?</Header2>
                                                <Description>
                                                            <Reason>
                                                                        <Value1>\b.TAM</Value1>
                                                                        <Value2>December </Value2>
                                                            </Reason>
                                                </Description>
                                                <Footer> TAM You do not qualify </Footer>
                                    </Rejection>
                        </MA>
            </CNRBenefitsDetails>

<Summary>
                        <Header>
                                    <TitleLogo>gif</TitleLogo>
                                    <MainTitle> Income</MainTitle>
                                    <SubTitle> benefits.</SubTitle>
                        </Header>
                        <[b]MA[/b]>
                                    <Logo>gif</Logo>
                                    <Title> Assistance</Title>
                                    <SubTitle>This was used </SubTitle>
                                    <SubTitle1> income:</SubTitle1>
                                    <SubDetails>
                                                <Sub tabletype="1M">
                                                            <Month1>05/2015</Month1>
                                                </Sub>
                                    </SubDetails>
                                    <Captions>
                                                <Caption id="1">I</Caption>
                                                <Caption id="2">-D</Caption>
                                                <Caption id="3">-E</Caption>
                                                <Caption id="4">=N </Caption>
                                                <Caption id="5"> limit </Caption>
                                    </Captions>
                                    <Summary>
                                                <Amount id="1" >$1,800.00</Amount>
                                                <Amount id="2" >$.00</Amount>
                                                <Amount id="3" >$.00</Amount>
                                                <Amount id="4" >$1,800.00</Amount>
                                                <Amount id="5" >$2,550.00</Amount>
                                    </Summary>
                                    <Footer>
                                                <Text1> income.</Text1>
                                                <Text2> use.</Text2>
                                                <Text4> use.</Text4>
                                                <Text5> limit.</Text5>
                                    </Footer>
                        </[b]MA[/b]>
                        <Footer>index </Footer>
            </Summary>

Open in new window


the xslt i am working with

<xsl:stylesheet version="1.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="CNRBenefitsDetails/MA">
        <xsl:variable name="ename">
            <xsl:text>MA</xsl:text>
            <xsl:if test="Rejection/@type='STOP'">
                <xsl:text>R</xsl:text>
            </xsl:if>
            <xsl:if test="Approval/MAQualified/Person/Prescription !=''">
                <xsl:text>P</xsl:text>
            </xsl:if>
        </xsl:variable>
        <xsl:element name="{$ename}"> <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>

<xsl:template match="Summary/MA">
        <xsl:variable name="ename">
            <xsl:text>MA</xsl:text>
            <xsl:if test="Sub/@tabletype='1M'">
                <xsl:text>o</xsl:text>
            </xsl:if>
          </xsl:variable>
        <xsl:element name="{$ename}"> <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window


Thank you for the help.
0
 

Author Comment

by:sri1209
ID: 40571284
I've requested that this question be deleted for the following reason:

sorry wrong question
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40571285
you can't close a question with a correct answer given
0
 

Author Comment

by:sri1209
ID: 40571289
sorry Geert Bormans , i had the wrong xml in the subsequent comments  and i was not able to edit the question, so not knowing how to proceed , i just tried to delete the question , but as far as the original question is concerned that has been working with your solution , thank you very much , i will try to ask a new question for this specific scenario.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40571324
Anyway, whilst we continue with this question ...

Your XML is not well formed
- it does not have a root element
- <MA> is not allowed as tagname (unless you just wanted to bold the tagname?

Your test is wrong... Sub is not a child of MA, there is SubDetails in between

Chenge the test like this
            <xsl:if test="SubDetails/Sub/@tabletype='1M'">
                <xsl:text>o</xsl:text>
            </xsl:if>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40571327
No need to ask a new question if the above answer helps you.

If you "delete" a question, it will be removed from teh database and will no longer be accessible.
Don't worry, you can continue here, will continue to provide a solutuion here and will ignore the XML you posted, simply dump a new one here
0
 

Author Comment

by:sri1209
ID: 40571351
Thank you very much , it worked perfectly.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40571392
welcome
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now