Link to home
Start Free TrialLog in
Avatar of jefftk99
jefftk99

asked on

XSLTC error...java.lang.RuntimeException: Namespace for prefix has not been declared.

I am having a problem using XSLTC.  I was currently using the default Xalan processor and tried to switch to XSLTC by setting the appropriate property.  See below

Was this:
  System.setProperty("javax.xml.transform.TransformerFactory",
                           "org.apache.xalan.processor.TransformerFactoryImpl");

It is now this:
  System.setProperty("javax.xml.transform.TransformerFactory",
                           "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
       
        this.strSheetName = p_strSheetName;
        TransformerFactory oFactory = TransformerFactory.newInstance();
        this.templates = oFactory.newTemplates(new StreamSource(p_oStyleSheetValue));

When I made this change, all of my stylesheets compiled successfully.  However, when I tried to perform a transform of XML I get the following error.
java.lang.RuntimeException: Namespace for prefix 'srvc' has not been declared.

Here is my stylesheet
****
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:srvc="http://doc.state.nc.us/1.0/doc-services"
      xmlns:data="http://doc.state.nc.us/1.0/doc-data"      
      xmlns:java="xalan://us.nc.state.doc.facade.ejb.asicache.ASICacheUtil"
      xmlns:codeConstants="xalan://us.nc.state.doc.ws.core.constants.CodeConstants"
      exclude-result-prefixes="java codeConstants" version="2.0">

      <!-- THESE ARE VARIABLES SET FROM OUTSIDE THE STYLESHEET -->
      <xsl:param name="TOTALRECORDS" />
      <xsl:param name="SERVICENAME" />

      <xsl:output method="xml" indent="no" encoding="UTF-8" version="1.0" />
      <xsl:template match="/">
            
            <xsl:variable name="COMPLETESERVICENAME" select="concat('srvc:', $SERVICENAME, 'Response')"/>
             <xsl:element name="{$COMPLETESERVICENAME}">      
                  <data:FacilityId><xsl:value-of select = "./JobClassificationInquireSummary/facilityId" /></data:FacilityId>
                  <data:TotalRecords><xsl:value-of select = "$TOTALRECORDS" /></data:TotalRecords>                  
                  <srvc:JobClassificationSummaryList>
                        <xsl:for-each select="./JobClassificationInquireSummary/jobClassificationSummaryList/JobClassificationItem">
                              <srvc:JobClassificationSummaryListElement>
                                    <data:StaffId><xsl:value-of select="./staffId" /></data:StaffId>
                                    <data:StaffIdName><xsl:value-of select="./staffName" /></data:StaffIdName>
                                    <data:StaffPositionNumber><xsl:value-of select="./positionNumber" /></data:StaffPositionNumber>                                                
                              </srvc:JobClassificationSummaryListElement>
                        </xsl:for-each>
                  </srvc:JobClassificationSummaryList>
            </xsl:element>
      </xsl:template>
</xsl:stylesheet>

****

Here is a sample XML file that I transform.
****

<?xml version="1.0" encoding="UTF-8"?>
<JobClassificationInquireSummary>
    <facilityId>1234</facilityId>
    <jobClassificationSummaryList>          
        <JobClassificationItem>
            <staffId>XXX01</staffId>
            <staffName>Jane Doe</staffName>
            <positionNumber>00000</positionNumber>
            <assignedDate class="sql-date">2000-07-24</assignedDate>
            <statusCode>A</statusCode>
            <statusDate class="sql-date">2006-05-15</statusDate>
            <staffType>DC</staffType>
            <jobClassCode>00000</jobClassCode>
            <workAssignment>A34</workAssignment>
            <licenseNumber/>
            <licenseExpirationDate class="sql-date">0001-01-01</licenseExpirationDate>
            <workPhoneNumber>1234567890</workPhoneNumber>
            <workPhoneExt>999</workPhoneExt>
            <pasgePhoneNumber/>
            <homePhoneNumber/>
            <apptCalLimitSunday/>
            <apptCalLimitMonday/>
            <apptCalLimitTuesday/>
            <apptCalLimitWednesday/>
            <apptCalLimitThursday/>
            <apptCalLimitFriday/>
            <apptCalLimitSaturday/>
            <userId/>
            <authlevel>B3</authlevel>
            <defaultPrinter/>
            <secAdmFacility>3060</secAdmFacility>
            <supervisorNumber>XXX03</supervisorNumber>
            <dateofUpdate class="sql-date">2006-03-06</dateofUpdate>
            <timeOfUpdate class="sql-time">14:06:25</timeOfUpdate>
            <staffOfUpdate>ZZZ04</staffOfUpdate>
            <faxNumber>1234567890</faxNumber>
            <courierNumber>000001</courierNumber>
            <idCardIssueNumber>02</idCardIssueNumber>
            <unitId/>
            <altPhoneNumber/>
            <idVerificationCode>V</idVerificationCode>
            <mailingAddress>701 FOO BAR RD.</mailingAddress>
            <city>NOWHERE</city>
            <state>XX</state>
            <zip>12345</zip>
            <emailAddress/>
            <workAddress/>
            <workCity/>
            <workState/>
            <workZip/>
            <pagerExt/>
            <functionalAreaCode/>
            <advDaysToBeScheduled/>
            <minDaysToBeScheduled/>
            <genderCode/>
            <race/>
            <height/>
            <weight/>
            <hairCode/>
            <eyeColorCode/>
        </JobClassificationItem>
    </jobClassificationSummaryList>
    <returnCode>0000</returnCode>
    <returnMessage>Success</returnMessage>
    <errorSeverity>Info</errorSeverity>
</JobClassificationInquireSummary>

****


Any help is much appreciated!
Thank you in advance.

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Hi jefftk99,
> XSLTC

have you tried setting the version to "1.0"?

Cheers!
Avatar of jefftk99
jefftk99

ASKER

Unfortunately, I have already given that a try.  No Luck.
I Have found the problem.  I needed to include a namespace attribute.  See below

 <xsl:element name="{$COMPLETESERVICENAME}">    

new code

 <xsl:element name="{$COMPLETESERVICENAME}" namespace="some name space">

Thanks for the help !    
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial