0

I'm using saxon 9he, eclipse, tomcat 7. I'm going to paraphrase the code. When I run the transformation I get all the values I want in the for each except InsurerId. If I change (in debug) the xml to InsurerId2 and xsl to get the value of InsurerId2 it works. I have two fields that are give me this trouble, I was at one time able to get this between that time I have added changed to xsl 2.0,changed from saxon 6, added current-date function . This is very confusing please help.

xml

<PersDriver id="001">
                <ItemIdInfo>
                     <InsurerId>001</InsurerId>
                </ItemIdInfo>
                <GeneralPartyInfo>
                     <NameInfo>
                          <PersonName>
                               <Surname>test</Surname>
                               <GivenName>test</GivenName>
                               <OtherGivenName>
                               </OtherGivenName>
                               <TitlePrefix>
                               </TitlePrefix>
                               <NameSuffix>
                               </NameSuffix>
                          </PersonName>
                          <TaxIdentity>
                               <TaxIdTypeCd>SSN</TaxIdTypeCd>
                               <TaxId> 999999999999</TaxId>
                          </TaxIdentity>
                     </NameInfo>
                </GeneralPartyInfo>
                <DriverInfo>
                     <PersonInfo>
                          <GenderCd>M</GenderCd>
                          <BirthDt>1979-08-23</BirthDt>
                          <MaritalStatusCd>
                          </MaritalStatusCd>
                     </PersonInfo>
                     <DriversLicense>
                          <LicensedDt>2007-08-23</LicensedDt>
                          <DriversLicenseNumber>99999999</DriversLicenseNumber>
                          <StateProvCd>TN</StateProvCd>
                     </DriversLicense>
                </DriverInfo>
                <PersDriverInfo>
                     <DefensiveDriverDt />
                     <DriverRelationshipToApplicantCd>
                     </DriverRelationshipToApplicantCd>
                     <DriverTrainingInd />
                     <GoodDriverInd />
                     <GoodStudentCd />
                </PersDriverInfo>
           </PersDriver>

xsl

<xsl:for-each select="$RsXml/InsuranceSvcRs/com.csc_PolicyOrderCurrentCarrierInqRs/PersDriver">



        <driver type_code="DP" id="0">

        <prefix>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/TitlePrefix"/>
        </prefix>
        <firstname>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/GivenName"/>
        </firstname>
        <midname/>
        <lastname>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/Surname"/>           
        </lastname>
        <suffix>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/NameSuffix"/>
        </suffix>
        <sex>
            <xsl:value-of select="DriverInfo/PersonInfo/GenderCd"/>
        </sex>
        <dateofbirth>
            <xsl:value-of select="DriverInfo/PersonInfo/BirthDt"/>
        </dateofbirth>
        <ssn>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/TaxIdentity/TaxId"/>            
        </ssn>
        <maritalstatus>
            <xsl:value-of select="DriverInfo/PersonInfo/MaritalStatusCd"/>
        </maritalstatus>
        <occupation/>
        <homephone/>
        <workphone/>
        <cellphone/>
        <homeemail/>
        <workemail/>
        <licensestate>
            <xsl:value-of select="DriverInfo/DriversLicense/StateProvCd"/>
        </licensestate>
        <licensenumber>
            <xsl:value-of select="DriverInfo/DriversLicense/DriversLicenseNumber"/>
        </licensenumber>
        <xsl:message>
        <TEST>
        <xsl:value-of select="ItemIdInfo/InsurerId"/>
        </TEST>

        </xsl:message>
         <xsl:choose>          
            <xsl:when test="@id=001">             
               <namedinsured>true</namedinsured>    
            </xsl:when>
            <xsl:otherwise>
                <namedinsured>false</namedinsured>             
            </xsl:otherwise>
         </xsl:choose>

        <namedinsured2></namedinsured2>
        <driver></driver>
        <livewithparents/>
        <vehicledriven/>
        <driveworkschool/>
        <keptatcollege/>
        <beensuspended/>
        <business></business>
        <beenarrested/>
        <client_id></client_id>
        <violations/>
        <accidents/>
    </driver>
        </xsl:for-each> 

</xsl:copy>
</xsl:template>
Justin Cox
  • 326
  • 4
  • 22

3 Answers3

0

I cannot reproduce the problem:

This transformation (the provided one, but with corrected syntax and within a match-template):

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="PersDriver">
        <driver type_code="DP" id="0">

        <prefix>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/TitlePrefix"/>
        </prefix>
        <firstname>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/GivenName"/>
        </firstname>
        <midname/>
        <lastname>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/Surname"/>
        </lastname>
        <suffix>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/PersonName/NameSuffix"/>
        </suffix>
        <sex>
            <xsl:value-of select="DriverInfo/PersonInfo/GenderCd"/>
        </sex>
        <dateofbirth>
            <xsl:value-of select="DriverInfo/PersonInfo/BirthDt"/>
        </dateofbirth>
        <ssn>
            <xsl:value-of select="GeneralPartyInfo/NameInfo/TaxIdentity/TaxId"/>
        </ssn>
        <maritalstatus>
            <xsl:value-of select="DriverInfo/PersonInfo/MaritalStatusCd"/>
        </maritalstatus>
        <occupation/>
        <homephone/>
        <workphone/>
        <cellphone/>
        <homeemail/>
        <workemail/>
        <licensestate>
            <xsl:value-of select="DriverInfo/DriversLicense/StateProvCd"/>
        </licensestate>
        <licensenumber>
            <xsl:value-of select="DriverInfo/DriversLicense/DriversLicenseNumber"/>
        </licensenumber>
        <xsl:message>
        <TEST>
        <xsl:value-of select="ItemIdInfo/InsurerId"/>
        </TEST>

        </xsl:message>
         <xsl:choose>
            <xsl:when test="@id=001">
               <namedinsured>true</namedinsured>
            </xsl:when>
            <xsl:otherwise>
                <namedinsured>false</namedinsured>
            </xsl:otherwise>
         </xsl:choose>

        <namedinsured2></namedinsured2>
        <driver></driver>
        <livewithparents/>
        <vehicledriven/>
        <driveworkschool/>
        <keptatcollege/>
        <beensuspended/>
        <business></business>
        <beenarrested/>
        <client_id></client_id>
        <violations/>
        <accidents/>
    </driver>
</xsl:template>
</xsl:stylesheet>

when applied on the provided XML document:

<PersDriver id="001">
    <ItemIdInfo>
        <InsurerId>001</InsurerId>
    </ItemIdInfo>
    <GeneralPartyInfo>
        <NameInfo>
            <PersonName>
                <Surname>DALESANDRO</Surname>
                <GivenName>MAKIEH</GivenName>
                <OtherGivenName>
                </OtherGivenName>
                <TitlePrefix>
                </TitlePrefix>
                <NameSuffix>
                </NameSuffix>
            </PersonName>
            <TaxIdentity>
                <TaxIdTypeCd>SSN</TaxIdTypeCd>
                <TaxId>666-18-6774</TaxId>
            </TaxIdentity>
        </NameInfo>
    </GeneralPartyInfo>
    <DriverInfo>
        <PersonInfo>
            <GenderCd>M</GenderCd>
            <BirthDt>1979-08-23</BirthDt>
            <MaritalStatusCd>
            </MaritalStatusCd>
        </PersonInfo>
        <DriversLicense>
            <LicensedDt>2007-08-23</LicensedDt>
            <DriversLicenseNumber>882827206</DriversLicenseNumber>
            <StateProvCd>TN</StateProvCd>
        </DriversLicense>
    </DriverInfo>
    <PersDriverInfo>
        <DefensiveDriverDt />
        <DriverRelationshipToApplicantCd>
        </DriverRelationshipToApplicantCd>
        <DriverTrainingInd />
        <GoodDriverInd />
        <GoodStudentCd />
    </PersDriverInfo>
</PersDriver>

produces exactly the expected output (containing <namedinsured>true</namedinsured>):

<driver type_code="DP" id="0">
   <prefix>
                </prefix>
   <firstname>MAKIEH</firstname>
   <midname/>
   <lastname>DALESANDRO</lastname>
   <suffix>
                </suffix>
   <sex>M</sex>
   <dateofbirth>1979-08-23</dateofbirth>
   <ssn>666-18-6774</ssn>
   <maritalstatus>
            </maritalstatus>
   <occupation/>
   <homephone/>
   <workphone/>
   <cellphone/>
   <homeemail/>
   <workemail/>
   <licensestate>TN</licensestate>
   <licensenumber>882827206</licensenumber>
   <namedinsured>true</namedinsured>
   <namedinsured2/>
   <driver/>
   <livewithparents/>
   <vehicledriven/>
   <driveworkschool/>
   <keptatcollege/>
   <beensuspended/>
   <business/>
   <beenarrested/>
   <client_id/>
   <violations/>
   <accidents/>
</driver>
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • This xml is a parm passed on to the xsl. Do you think the ide or generated parm could be causing this quirky problem? Thanks – Justin Cox Dec 06 '12 at 18:10
  • @JustinCox, If what is passed is an XmlDocument object, then the result must be the same. If however, you are passing the XML as text, then this is an error -- something that shouldn't be done. – Dimitre Novatchev Dec 06 '12 at 18:27
  • It's a DOM, Michael told me to use XdmNode instead, working on that change. Also the xsl is cached in this app. I don't understand why when I change the element name it works, seems like a cached issue in that regard. – Justin Cox Dec 06 '12 at 18:31
  • http://stackoverflow.com/questions/13381698/pass-xml-document-as-parameter-to-xsl – Justin Cox Dec 06 '12 at 18:34
0

If you want to avoid having InsurerId, you can try this following. test.xml contains your xml.

try {

            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("D:\\Loic_Workspace\\Test2\\res\\test.xml"));

            XPath xpath = XPathFactory.newInstance().newXPath();
            NodeList ndList = (NodeList) xpath.evaluate("PersDriver/*[not(name()='ItemIdInfo')]", doc, XPathConstants.NODESET);


            for(int i=0;i<ndList.getLength();i++){
                System.out.println(ndList.item(i).getNodeName()+" "+ndList.item(i).getTextContent());
            }


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

This will ouput in the console :

GeneralPartyInfo 


DALESANDRO
MAKIEH








SSN
666-18-6774



DriverInfo 

M
1979-08-23




2007-08-23
882827206
TN


PersDriverInfo 

You can go check if a node contains child nodes by doing this following, for example :

if(ndList.item(i).hasChildNodes()){
....
}

So you could check if it's necessary to fetch the childen node value this way. That's why I have all that blank space from the console output.

Tell me if it's helps ;)

0

I was building the parm xml with saxon Impl... Removed it and it now works???

Before

DocumentBuilderFactory dfactory =
        DocumentBuilderFactory.newInstance("net.sf.saxon.dom.DocumentBuilderFactoryImpl",null); 
DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); 
org.w3c.dom.Document document = docBuilder.parse(new InputSource(new StringReader(xmlSource)));
Transformer transformer = xsl.newTransformer();
transformer.setParameter("RsXml", document.getDocumentElement());

Changed back to

DocumentBuilderFactory dfactory =DocumentBuilderFactory.newInstance();
Justin Cox
  • 326
  • 4
  • 22