RE: [xsl] How to get XSL transform this XML

Subject: RE: [xsl] How to get XSL transform this XML
From: "WATKIN-JONES,ADAM (HP-UnitedKingdom,ex1)" <adam_watkin-jones@xxxxxx>
Date: Tue, 26 Mar 2002 15:17:40 -0000
Here's one approach.  However, this is fairly ugly (as is the starting point
for the problem!) and maybe one of the stars of the list can think of a
better way! HTH, Adam


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

    <xsl:output method="xml" indent="yes"/>

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

    <xsl:template match="DocumentDetails/*[. = 'CLOSING CONDITIONS:']">
        <xsl:copy-of select="."/>
        <xsl:variable name="nTagNum" select="substring-after(name(),
'ConditionText')"/>
        <xsl:message><xsl:value-of select="$nTagNum"/></xsl:message>
        <xsl:element name="{concat('ConditionText', $nTagNum + 1)}">
            <xsl:text>                 X This is Standard Condition
1</xsl:text>
        </xsl:element>
        <xsl:element name="{concat('ConditionText', $nTagNum + 2)}">
            <xsl:text>                 X This is Standard Condition
2</xsl:text>
        </xsl:element>
        <xsl:element name="{concat('ConditionText', $nTagNum + 3)}">
            <xsl:text>                 X This is Standard Condition
3</xsl:text>
        </xsl:element>
    </xsl:template>

    <xsl:template match="DocumentDetails/*[preceding-sibling::*[. = 'CLOSING
CONDITIONS:']]">
        <xsl:variable name="nTagNum" select="substring-after(name(),
'ConditionText')"/>
        <xsl:element name="{concat('ConditionText', $nTagNum + 3)}">
            <xsl:copy-of select="text()"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>


-----Original Message-----
From: Manoj Jha

Hi,

I need XSL to transform the following XML. Could some guru help me out ?

Below is a sample XML that I want to transform, and the description of the 
problem:

<?xml version="1.0"?>
<DocumentRequest>
  <Director>
    <DocumentName>UnderwritingAnalysisPage1</DocumentName>
    <DeliveryMedium>browser</DeliveryMedium>
    <ApplicationId>15</ApplicationId>
    <PostPay>no</PostPay>
  </Director>
  <DocumentDetails>
    <BorrowerName>WALZER, CLIFFORD S</BorrowerName>
    <LoanStatus>APPROVED</LoanStatus>
     .
     .
    <ConditionText1>PRIOR TO APPROVAL CONDITIONS - UGSI TO 
REVIEW:</ConditionText1>
    <ConditionText2>     </ConditionText2>
    <ConditionText3>PRIOR TO DOC CONDITIONS - UGSI TO 
REVIEW:</ConditionText3>
    <ConditionText4>     </ConditionText4>
    <ConditionText5>PRIOR TO CLOSING CONDITIONS - UGSI TO 
REVIEW:</ConditionText5>
    <ConditionText6>03/14/2002 _____ THANK YOU FOR CHOOSING UNITED GUARANTY.

  PLEASE INCLUDE A COPY OF </ConditionText6>
    <ConditionText7>                 THIS</ConditionText7>
     .
     .
    <ConditionText15>CLOSING CONDITIONS:</ConditionText15>
    <ConditionText16>                 X FINAL SIGNED T-I-L</ConditionText16>
    <ConditionText17>                 X FILE MUST CLOSE AS A 30 YEAR 
RATE/TERM REFINANCE</ConditionText17>
     .
     .
    <ConditionText44> </ConditionText44>
  </DocumentDetails>
</DocumentRequest>

The tag value "CLOSING CONDITIONS:" can appear as value of any of the 
ConditionText tags, but after the "PRIOR CONDITIONS".
The XSL stylesheet should locate the "CLOSING CONDITIONS:" value, and insert

3 new predefined fixed ConditionText nodes after
that node. All the remaining ConditionText nodes will show this change in 
the result tree by having their count incremented as
shown in the transformed XML below:

<?xml version="1.0"?>
<DocumentRequest>
  <Director>
    <DocumentName>UnderwritingAnalysisPage1</DocumentName>
    <DeliveryMedium>browser</DeliveryMedium>
    <ApplicationId>15</ApplicationId>
    <PostPay>no</PostPay>
  </Director>
  <DocumentDetails>
    <BorrowerName>WALZER, CLIFFORD S</BorrowerName>
    <LoanStatus>APPROVED</LoanStatus>
     .
     .
    <ConditionText1>PRIOR TO APPROVAL CONDITIONS - UGSI TO 
REVIEW:</ConditionText1>
    <ConditionText2>     </ConditionText2>
    <ConditionText3>PRIOR TO DOC CONDITIONS - UGSI TO 
REVIEW:</ConditionText3>
    <ConditionText4>     </ConditionText4>
    <ConditionText5>PRIOR TO CLOSING CONDITIONS - UGSI TO 
REVIEW:</ConditionText5>
    <ConditionText6>03/14/2002 _____ THANK YOU FOR CHOOSING UNITED GUARANTY.

  PLEASE INCLUDE A COPY OF </ConditionText6>
    <ConditionText7>                 THIS</ConditionText7>
     .
     .
    <ConditionText15>CLOSING CONDITIONS:</ConditionText15>
    <ConditionText16>                 X This is Standard Condition 
1</ConditionText16> <!-- These 3 conditions get inserted -->
    <ConditionText17>                 X This is Standard Condition 
2</ConditionText17>
    <ConditionText18>                 X This is Standard Condition 
3</ConditionText18>
    <ConditionText19>                 X FINAL SIGNED T-I-L</ConditionText19>

           <!-- ConditionText16 now becomes Condition19, and so on; the 
value for the node remains the same -->
    <ConditionText20>                 X FILE MUST CLOSE AS A 30 YEAR 
RATE/TERM REFINANCE</ConditionText20>
     .
     .
    <ConditionText47> </ConditionText47>
  </DocumentDetails>
</DocumentRequest>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread