Solved

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

Posted on 2015-01-25
11
95 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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. 
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

10 Experts available now in Live!

Get 1:1 Help Now