Subject: Re: [xsl] How To: XSL Template Setup, Names, Calling, Applying ? From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx> Date: Tue, 1 Mar 2011 23:44:31 -0500 |
The biggest problem I can see is some confusion between regular templates and named templates. A regular template has a "match" attribute that contains an XPath "pattern" that describes the types of nodes it can process. Regular templates are invoked using xsl:apply-templates. Named templates have a "name" attribute and are invoked using xsl:call-template. The code does an apply-templates on the "Person" element, but there is no regular template to match it. It also has an "InsuredPerson" named template that is never called. These would appear to be missing each other. Similarly, the apparent attempts to call the "InsuredAddress" and "InsuredPhone" templates are using apply-templates, rather than call-template. The call to the "StateTypeCode" template attempts to pass the "AddressStateTC" element from the input, but since it isn't a child of the "Policy" element that is being processed at that point, it will pass nothing, instead. This needs an XPath expression that properly navigates up and out of the Policy element and down to the actual location of the desired element. Finally, the main template should either match the "TXLife" element, rather than "node()", which will cause it to be invoked for any node that doesn't match a more specific template, including elements and text nodes, which is certainly not going to give the desired result. -Brandon :) On Tue, Mar 1, 2011 at 8:31 PM, Jeffry Proctor <jpgmt@xxxxxxxxxxxxx> wrote: > ASP.Net 2008 .Net ver 3.5, Linq with XslCompiledTransform, XSLT 1.0 (asumed), > > The following is a subset of my current version that isn't working, but works > better than what I've included here. However, rather than fix a much longer more > involved XSL I'm opting to work on this flawed but more simple version that > encompases most of what I need to occur in the larger version. > > I know that the way that I'm setting up my templates and calling/apply them is > not right, but with varying degrees of success, I've got a hodge-podge of > methods that I have no answer as to why it works when it does or doesn't. > > In a near perfect world someone could tell me, comment my bad setup > calls/applies and add a corrected with perhaps a comment or two and I'll do my > best to comprehend. > > > All comments are welcomed. Thanks in advance... > > Did I mention that I'm relatively new to XSL? > > > > New Order info currently named person.xml > > <?xml version="1.0" encoding="iso-8859-1"?> > <TXLife> > <OrderInfo> > <CaseNo>0123456789ABCD</CaseNo> > </OrderInfo> > <Policy> > <PolicyStatus>PROPOSED</PolicyStatus> > <OrderInfo> > <CaseNo>0123456789ABCD</CaseNo> > </OrderInfo> > <uPlanDesc>Select Term 20</uPlanDesc> > </Policy> > <Person> > <FirstName>James</FirstName> > <LastName>Baumbach</LastName> > <uSex>Male</uSex> > <uBirthDate>1975-01-01</uBirthDate> > <Address> > <AddressTypeCode>Residence</AddressTypeCode> > <Line1>12349 Any Street</Line1> > <City>Towne</City> > <AddressStateTC>WI</AddressStateTC> > <Zip>89089</Zip> > </Address> > </Person> > </TXLife> > > XSL > <?xml version="1.0" encoding="utf-8" ?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns="http://ACORD.org/Standards/Life/2" > > > <xsl:output method="xml" indent="yes"/> > <!-- var Name = Insured, value unique Int suffix ie: Insured_12345678 --> > <xsl:variable name="Insured" ></xsl:variable> > > <!-- Main-Template... --> > > <xsl:template match="node()"> > <TXLife> > <UserAuthRequest> > <!-- Elements omitted... --> > </UserAuthRequest> > <TXLifeRequest> > <OLifE> > <Holding id="Holding_167392"> > <xsl:apply-templates select="Policy"/> > </Holding> > <Party id="InsuredParty_5293884"> > <xsl:apply-templates select="Person"/> > </Party> > </OLifE> > </TXLifeRequest> > </TXLife> > </xsl:template> > > <!-- End Main Template --> > <!-- Begin Sub-Templates... --> > > <xsl:template match="Policy"> > <!-- Often no policy number exists at this point in time--> > <Policy id="Pending_Policy_TT5SMM777" CarrierPartyID="CarrierParty_167393"> > <PolicyNumber><xsl:value-of select="OrderInfo/CaseNo"/></PolicyNumber> > <PlanName><xsl:value-of select="uPlanDesc"/></PlanName> > <PolicyStatus> > <xsl:attribute name="tc"> > <xsl:call-template name="PolicyStatus"> > <xsl:with-param name="PolicyStatus" select="PolicyStatus"/> > </xsl:call-template> > </xsl:attribute> > <xsl:value-of select="PolicyStatus"/> > </PolicyStatus> > <Life> > <FaceAmt><xsl:value-of select="uPolAmount"/></FaceAmt> > </Life> > <ApplicationInfo> > <ApplicationJurisdiction> > <xsl:attribute name="tc"> > <xsl:call-template name="StateTypeCode"> > <xsl:with-param name="stateCode" select="AddressStateTC"/> > </xsl:call-template> > </xsl:attribute> > <xsl:value-of select="AddressStateTC"/> > </ApplicationJurisdiction> > </ApplicationInfo> > </Policy> > </xsl:template> > > <xsl:template name="InsuredPerson"> > <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="uSex='Male'">1</xsl:when> > <xsl:when test="uSex='Female'">2</xsl:when> > </xsl:choose> > </xsl:attribute> > <xsl:value-of select="uSex"/> > </Gender> > <BirthDate><xsl:value-of select="BirthDate"/></BirthDate> > <DriversLicenseNum>none</DriversLicenseNum> > <xsl:apply-templates select="InsuredAddress"/> > <xsl:apply-templates select="InsuredPhone"/> > </Person> > </xsl:template> > > <xsl:template name="InsuredAddress"> > <Address> > <AddressTypeCode> > <xsl:attribute name="tc"> > <xsl:choose> > <xsl:when test="AddressTypeCode='Residence'">1</xsl:when> > <xsl:when test="AddressTypeCode='Business'">2</xsl:when> > </xsl:choose> > </xsl:attribute> > <xsl:value-of select="AddressTypeCode"/> > </AddressTypeCode> > <Line1> > <xsl:value-of select="Line1"/> > </Line1> > <City> > <xsl:value-of select="City"/> > </City> > <AddressStateTC> > <xsl:attribute name="tc"> > <xsl:call-template name="StateTypeCode"> > <xsl:with-param name="stateCode" select="AddressStateTC"/> > </xsl:call-template> > </xsl:attribute> > <xsl:value-of select="AddressStateTC"/> > </AddressStateTC> > <State> > <xsl:value-of select="AddressStateTC"/> > </State> > <Zip>89089</Zip> > </Address> > </xsl:template> > <xsl:template match="InsuredPhone"> > <Phone> > <PhoneTypeCode tc="1">Home</PhoneTypeCode> > <AreaCode>890</AreaCode> > <DialNumber>8908908</DialNumber> > </Phone> > </xsl:template> > > <!-- Re-Useable StateTypeCode Lookup --> > <xsl:template name="StateTypeCode"> > <xsl:param name="stateCode"></xsl:param> > <xsl:choose> > <xsl:when test="$stateCode ='AL'">1</xsl:when> > <xsl:when test="$stateCode ='AK'">2</xsl:when> > <xsl:when test="$stateCode ='CA'">6</xsl:when> > <!-- dev version with omitted states --> > <xsl:otherwise> > <xsl:value-of select="concat('[Error: StateCode = ', $stateCode, ']')"/> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > <xsl:template name="PolicyStatus"> > <xsl:param name="PolicyStatus"></xsl:param> > <xsl:choose> > <xsl:when test="$PolicyStatus='UNKNOWN'">0</xsl:when> > <xsl:when test="$PolicyStatus='ACTIVE'">1</xsl:when> > <xsl:when test="$PolicyStatus='INACTIVE'">2</xsl:when> > <xsl:when test="$PolicyStatus='PENDING'">8</xsl:when> > <xsl:when test="$PolicyStatus='PROPOSED'">12</xsl:when> > <!-- dev version with omitted PolicyStatus --> > <xsl:when test="$PolicyStatus='OTHER'">2147483647</xsl:when> > <xsl:otherwise> > <xsl:value-of select="concat('[Error: PolicyStatus = ', $PolicyStatus, ']')"/> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > <!-- End Sub Templates --> > > </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How To: XSL Template Setup, N, Jeffry Proctor | Thread | [xsl] [job] Web Developer, 1 year, , James Cummings |
[xsl] How To: XSL Template Setup, N, Jeffry Proctor | Date | [xsl] [job] Web Developer, 1 year, , James Cummings |
Month |