Altova Mailing List Archives


[xsl] Multiple Template Matchingm, Attributes & Complex XML

From: Jeffry Proctor <jpgmt@---------.--->
To: xsl-list@-----.------------.---
Date: 2/25/2011 5:13:00 PM
ASP.Net 2008, Linq XmlCompiledTransform, XSLT ver 1.0 I assume?

1. Limited as I am, the Person node/element & attribute is updating correctly; 
How do I add other node/element?
I assume it will be to remove Person as the top level match, but I'm not finding 
examples for making XML, many for HTML and mutilple tables sometimes nesting, 
but for some reason that doesn't speak to me.

2. Is there a way to have another xml file as a lookup list for attributes like 
gender typeCode tc or state typeCode tc so that the one XSL is easier to manage? 
(very low priority at this time, worst case, I can return those values 
discretely based on an SQL lookup that returns only the one state:tc relation 
value.)

XML Output Frag...
      </Holding>
      <Party id="InsuredParty_5293884">
        <Person>
          <FirstName>Rogerina</FirstName>
          <LastName>Proctor</LastName>
          <Gender tc="1">Male</Gender>
          <BirthDate>1975-01-01</BirthDate>
          <DriversLicenseNum>none</DriversLicenseNum>
          <DriversLicenseState tc="17">IL</DriversLicenseState>
        </Person>
        <Address> <!-- currently hardcoded... -->
          <AddressTypeCode tc="1">Residence</AddressTypeCode>
          <Line1>123 Superior Street</Line1>
          <City>City</City>
          <AddressStateTC tc="">
          </AddressStateTC>
          <Zip>89089</Zip>
        </Address>


XML Frag...
<?xml version="1.0" encoding="iso-8859-1"?>
<TXLife>
    <Person>
        <FirstName>Rogerina</FirstName>
        <LastName>Proctor</LastName>
        <Gender>Male</Gender>
        <BirthDate>1975-01-01</BirthDate>
    </Person>
   <!-- How to add: AddressStateTC to the XSL? -->
    <Address>
       <AddressStateTC>CA</AddressStateTC>
    </Address>
</TXLife>

 XSL Frag...
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <!-- this wroks ONLY for Person, how do I add other items to match 
on: AddressStateTC -->
    <xsl:template match="Person">
        <TXLife>
            <UserAuthRequest>elements omitted </UserAuthRequest>
            <TXLifeRequest>
                <OLifE>
                    <Holding id="Holding_167392">elements omitted
                        </Policy>elements omitted</Policy>
                    </Holding>
                    <Party id="InsuredParty_5293884">
                        <xsl:apply-templates>
                            <Person>
                                <FirstName><xsl:value-of 
select="FirstName"/></FirstName>
                                <LastName><xsl:value-of 
select="LastName"/></LastName>
                                <Gender>
                                    <xsl:attribute name="tc">
                                        <xsl:choose>
                                            <xsl:when 
test="Gender='Male'">1</xsl:when>
                                            <xsl:when 
test="Gender='Female'">2</xsl:when>
                                        </xsl:choose>
                                    </xsl:attribute>
                                    <xsl:value-of select="Gender"/>
                                </Gender>
                                <BirthDate><xsl:value-of 
select="BirthDate"/></BirthDate>
                                <DriversLicenseNum>none</DriversLicenseNum>
                                <DriversLicenseState 
tc="17">IL</DriversLicenseState>
                            </Person>
                        </xsl:apply-templates>
                        <Address>elements omitted
                            <!--
                                  Important question: How do I add an Address 
template?
                            -->
                            <AddressStateTC>
                                <xsl:attribute name="tc">
                                    <xsl:choose>
                                        <!-- this is a low priority question...
                                          Is there a way to add either another 
XSL for adding the attribute? 

                                        -->
                                        <xsl:when 
test="AddressStateTC='AL'">1</xsl:when>
                                        <xsl:when 
test="AddressStateTC='AK'">2</xsl:when>
                                        other states omitted...
                                    </xsl:choose>
                                </xsl:attribute>
                                <xsl:value-of select="AddressStateTC"/>
                            </AddressStateTC>
                        </Address>
                        <Phone>elements omitted</Phone>
                    </Party>
                </OLifE>
            </TXLifeRequest>
        </TXLife>
    </xsl:template>    
</xsl:stylesheet>

TIA
JeffPGMT...

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.