Solved

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

Posted on 2015-01-25
11
97 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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