Solved

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

Posted on 2015-01-25
11
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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