Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2004, 07:03 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to move sections

Hi All,

I am a newbie of XSLT and I am struggling with a problem of trying to move some of sections under other sections under a condition of their ID matching. I hope someone here could help me or give me an example on how to do it. I searched on the Internet for the whole day but couldn’t get much help. Thank you very much in advance. Following is the original XML:


<CBABatchHeader ProductionData="Value">
  <CBAPartySegment>
    <RevisionNumber>V2.7</RevisionNumber>
      <CBAParty>
    <RelatedEntityRef RelatedID="A1"/>
    <ApplicationFlags FlagType="ProofIncome" FlagValue="Yes"/>
      </CBAParty>
      <CBAParty>
    <RelatedEntityRef RelatedID="A2"/>
    <ApplicationFlags FlagType="ProofIncome" FlagValue="Yes"/>
      </CBAParty>
    </CBAPartySegment>

    <CBAProductSegment>
    <RevisionNumber>2.7</RevisionNumber>
    </CBAProductSegment>
    <LIXISegment>
    <ApplicationBatch>
        <Identifier UniqueID="LIXI-BATCH-01" Type="Value"/>
      <Application>
          <Identifier UniqueID="LIXI-APP-01" Type="LenderAssigned"/>
          <PartySegment>
          <Party Type="Applicant" PrimaryApplicant="Yes">
            <Identifier UniqueID="A1"/>
            <Person ************="Female" FirstHomeBuyer="No">
                <PersonName>
                <NameTitle Value="Mrs"/>
                <FirstName>Ann</FirstName> <OtherName>Sara</OtherName>
                <OtherName>Jessica</OtherName>
                <Surname>Brown</Surname>
                </PersonName>
            </Person>
          </Party>
          <Party Type="Applicant" PrimaryApplicant="No">
              <Identifier UniqueID="A2"/>
              <Person ************="Male" FirstHomeBuyer="No">
              <PersonName>
                <NameTitle Value="Mr"/>
                <FirstName>John</FirstName>
                <OtherName>Edward</OtherName>
                <Surname>Brown</Surname>
              </PersonName>
              </Person>
          </Party>
        </PartySegment>
      </Application>
      </ApplicationBatch>
   </LIXISegment>
</CBABatchHeader>


Basically, I want to move the two CBAParty sections under LIXISegment/ApplicationBatch/Application/ PartySegment/Party sections, and based on the RelatedID of CBAParty and the UniqueID of Party. I would also like to have the CBAParty section right after the Person section. Below is supposed to be the output.


<CBABatchHeader ProductionData="Value">
    <CBAPartySegment>
    <RevisionNumber>V2.7</RevisionNumber>
    </CBAPartySegment>
    <CBAProductSegment>
    <RevisionNumber>2.7</RevisionNumber>
    </CBAProductSegment>
    <LIXISegment>
    <ApplicationBatch>
        <Identifier UniqueID="LIXI-BATCH-01" Type="Value"/>
    <Application>
        <Identifier UniqueID="LIXI-APP-01" Type="LenderAssigned"/>
    <PartySegment>
        <Party Type="Applicant" PrimaryApplicant="Yes">
            <Identifier UniqueID="A1"/>
                <Person ************="Female" FirstHomeBuyer="No">
                <PersonName>
                    <NameTitle Value="Mrs"/>
                        <FirstName>Ann</FirstName>
                      <OtherName>Sara</OtherName>
                     <OtherName>Jessica</OtherName>
                    <Surname>Brown</Surname>
                </PersonName>
                </Person>
                        <CBAParty>
                <RelatedEntityRef RelatedID="A1"/>
                <ApplicationFlags FlagType="ProofIncome" FlagValue="Yes"/>
                </CBAParty>
            </Party>
            <Party Type="Applicant" PrimaryApplicant="No">
                <Identifier UniqueID="A2"/>
                    <Person ************="Male" FirstHomeBuyer="No">
                        <PersonName>
                        <NameTitle Value="Mr"/>
                        <FirstName>John</FirstName>
                        <OtherName>Edward</OtherName>
                        <Surname>Brown</Surname>
                          </PersonName>
                    </Person>
                        <CBAParty>
                        <RelatedEntityRef RelatedID="A2"/>
                        <ApplicationFlags FlagType="ProofIncome" FlagValue="Yes"/>
                    </CBAParty>
                </Party>
            </PartySegment>
        </Application>
    </ApplicationBatch>
    </LIXISegment>
</CBABatchHeader>


Thanks again for taking everyone’s time to have a look,

Cheers,

Ken
 
Old April 27th, 2004, 07:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Here you go Ken, any questions just ask.
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes"/>


    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>


    <xsl:template match="CBAParty"/>


    <xsl:template match="Party">

        <xsl:copy>

            <xsl:apply-templates select="@*"/>

            <xsl:apply-templates select="*"/>

            <xsl:copy-of select="/CBABatchHeader/CBAPartySegment/CBAParty[RelatedEntityRef/@RelatedID=current()/Identifier/@UniqueID]"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
rgds
Phil
 
Old April 27th, 2004, 06:36 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Phil,

Thank you very much for your quick response. Your code is working and very helpful as well as the comments. Thanks again.

Regards,

Ken


 
Old April 27th, 2004, 09:57 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Phil and everyone,

Now I got another problem while moving sections: two sections I need to rename their name after I move them under other sections. I modified your code but it seems only copying the two sections instead of matching their ID and then copying. Must be something wrong within my code. Following is my XSLT:


    <xsl:template match="FinancialSegment/ValueItem">

        <xsl:copy>

            <xsl:apply-templates select="@*"/>

            <xsl:apply-templates select="*"/>

            <CBAValueItem>
            <xsl:copy-of select="/CBABatchHeader/CBAFinancialSegment/ValueItem/*|@*[@RelatedID=current()/Identifier/@UniqueID]"/>
            </CBAValueItem>
        </xsl:copy>
    </xsl:template>


What I want to is to move the two CBAFinancialSegment/ValueItem sections under LIXISegment/ApplicationBatch/Application/FinancialSegment/ValueItem sections, basing on the RelatedID of CBAFinancialSegment/ValueItem and the UniqueID of FinancialSegment/ValueItem is matched. Then change the name of the sections that I have moved to CBAValueItem.

Here I included my original XML:

<CBABatchHeader ProductionData="Value">
    <CBAFinancialSegment>
      <RevisionNumber>2.7</RevisionNumber>
    <ValueItem>
        <RelatedEntityRef RelatedID="LIXI-FIN-VAL-01"/>
        <Asset Class="CurrentSecurity" ApplicantsEqualMortgagors="Yes">
            <RealEstate BridgingFlag="Yes"/>
        </Asset>
    </ValueItem>
    <ValueItem>
        <RelatedEntityRef RelatedID="LIXI-FIN-VAL-02"/>
        <Asset Class="CurrentSecurity" ApplicantsEqualMortgagors="No">
            <RealEstate BridgingFlag="No"/>
        </Asset>
    </ValueItem>
    </CBAFinancialSegment>
    <CBAProductSegment>
      <RevisionNumber>2.7</RevisionNumber>
    </CBAProductSegment>
    <LIXISegment>
        <ApplicationBatch>
            <Identifier UniqueID="LIXI-BATCH-01" Type="Value"/>
            <Application>
                <Identifier UniqueID="LIXI-APP-01" Type="LenderAssigned"/>
                <FinancialSegment>
            <ValueItem>
            <Identifier UniqueID="LIXI-FIN-VAL-01" Type="LenderAssigned"/>
            <Asset Class="CurrentSecurity">
                <RealEstate PrimarySecurity="No">
                <EstimatedValue EstimateBasis="ApplicantEstimate"/>
                </RealEstate>
            </Asset>
            </ValueItem>
            <ValueItem>
            <Identifier UniqueID="LIXI-FIN-VAL-02" Type="LenderAssigned"/>
            <Asset Class="CurrentSecurity">
                <RealEstate PrimarySecurity="Yes">
                <EstimatedValue EstimateBasis="CertifiedValuation"/>
                </RealEstate>
            </Asset>
            </ValueItem>
        </FinancialSegment>
            </Application>
        </ApplicationBatch>
    </LIXISegment>
</CBABatchHeader>


Following is the output that I want:

<CBABatchHeader ProductionData="Value">
    <CBAFinancialSegment>
      <RevisionNumber>2.7</RevisionNumber>
    </CBAFinancialSegment>
    <CBAProductSegment>
      <RevisionNumber>2.7</RevisionNumber>
    </CBAProductSegment>
    <LIXISegment>
        <ApplicationBatch>
            <Identifier UniqueID="LIXI-BATCH-01" Type="Value"/>
            <Application>
                <Identifier UniqueID="LIXI-APP-01" Type="LenderAssigned"/>
                <FinancialSegment>
            <ValueItem>
            <Identifier UniqueID="LIXI-FIN-VAL-01" Type="LenderAssigned"/>
            <Asset Class="CurrentSecurity">
                <RealEstate PrimarySecurity="No">
                <EstimatedValue EstimateBasis="ApplicantEstimate"/>
                </RealEstate>
            </Asset>
                        <CBAValueItem>
                    <RelatedEntityRef RelatedID="LIXI-FIN-VAL-01"/>
                        <Asset Class="CurrentSecurity" ApplicantsEqualMortgagors="Yes">
                            <RealEstate BridgingFlag="Yes"/>
                        </Asset>
                    </CBAValueItem>
            </ValueItem>
            <ValueItem>
            <Identifier UniqueID="LIXI-FIN-VAL-02" Type="LenderAssigned"/>
            <Asset Class="CurrentSecurity">
                <RealEstate PrimarySecurity="Yes">
                <EstimatedValue EstimateBasis="CertifiedValuation"/>
                </RealEstate>
            </Asset>
                        <CBAValueItem>
                    <RelatedEntityRef RelatedID="LIXI-FIN-VAL-02"/>
                    <Asset Class="CurrentSecurity" ApplicantsEqualMortgagors="No">
                    <RealEstate BridgingFlag="No"/>
                    </Asset>
                    </CBAValueItem>
            </ValueItem>
        </FinancialSegment>
            </Application>
        </ApplicationBatch>
    </LIXISegment>
</CBABatchHeader>


Thank you very much for taking your time to have a look.


All the best,

Ken


 
Old April 28th, 2004, 03:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Ken,

I don't have much time for an in-depth look at this at the moment, but a couple of things don't seem quite right with this bit:
    <xsl:template match="FinancialSegment/ValueItem">

        <xsl:copy>

            <xsl:apply-templates select="@*"/>

            <xsl:apply-templates select="*"/>

            <CBAValueItem>
            <xsl:copy-of select="/CBABatchHeader/CBAFinancialSegment/ValueItem/*|@*[@RelatedID=current()/Identifier/@UniqueID]"/>
            </CBAValueItem>
        </xsl:copy>
    </xsl:template>

The principle I applied in my previous post was:
1. add an empty template that matches the current position of the element you want to copy
2. add a template that matches the new parent node of the element you want to copy, and do the copying and matching within that template.
So, on that principle I think you should have an empty template matching CBAFinanacialSegment/ValueItem and your current template (shown above) should match the new parent Application/ValueItem.

Also, your matching XPath isn't quite right - you've missed out the RelatedEntityRef node and put the *|@* in the wrong place. I think you need:
<CBAValueItem>
<xsl:copy-of select="/CBABatchHeader/CBAFinancialSegment/ValueItem[RelatedEntityRef/@RelatedID=current()/Identifier/@UniqueID]/*|@*"/>
</CBAValueItem>

Let me know if this helps. If not, I'll try and find some time for a more detailed look.

rgds
Phil
 
Old April 28th, 2004, 06:44 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Phil,

Thanks for your time. I modified my XPath following your suggestion and it works! Thanks again,

Best wishes,

Ken







Similar Threads
Thread Thread Starter Forum Replies Last Post
Config Sections Muhammad Zeeshan BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 3rd, 2008 01:23 AM
About Sections in Crystal Reports Radhi Crystal Reports 1 September 7th, 2007 09:23 AM
I need Help Customizing the Grouping Sections ... raza_mrk36 Crystal Reports 2 January 21st, 2006 01:24 AM
Sections formatting s_chilkury Crystal Reports 0 December 21st, 2005 06:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.