XSLT Won't match any Element Names?!?!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    XSLT Won't match any Element Names?!?!

    Hi,

    I have the following XML

    Code:
    <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
    	<DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved>
    	<UserName>Bob</UserName>
    	<AssessmentName>Name of Assessment</AssessmentName>
    	<AssessmentID>AssID</AssessmentID>
    	<Sec_1_1189068258258>TEXT IN HERE</Sec_1_1189068258258>
    	<Sec_2_1188555751625_MC0>1</Sec_2_1188555751625_MC0>
    	<Sec_2_1188555751625_MC1>2</Sec_2_1188555751625_MC1>
    	<Sec_2_1188555751625_MC2>3</Sec_2_1188555751625_MC2>
    	<Sec_2_1188555751625_MC3>4</Sec_2_1188555751625_MC3>
    	<xSec_Sec_1>Step 2 of 8 - What happened?</xSec_Sec_1>
    	<xSec_Sec_2>Step 4 of 8  Assessor feedback</xSec_Sec_2>
    </AnswerList>
    and the following XSL
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<!-- Declare the output doctype -->
    	<!--xsl:output method="xml" indent="yes"  doctype-system="ims_qtiresv1p2.dtd"></xsl:output -->
    	<xsl:template match="/">
    		<qti_result_report>
    			<result>
    				<!-- Get the date that the assessment was submitted on -->
    				<xsl:variable name="DateSubmitted">
    					<xsl:value-of select="DateTimeLastSaved" />
    				</xsl:variable>
    
    				<!-- Get the Username of the user submitting the document -->
    				<xsl:variable name="UserName">
    					<xsl:value-of select="UserName" />
    				</xsl:variable>
    
    				<!-- Get the date that the assessment was submitted on -->
    				<xsl:variable name="AssessmentName">
    					<xsl:value-of select="AssessmentName" />
    				</xsl:variable>
    
    				<!-- Populate the Context -->
    				<xsl:element name="context">
    					<xsl:element name="name">
    						<xsl:value-of select="$UserName" />
    					</xsl:element>
    					<xsl:element name="generic_identifier">
    						<xsl:element name="type_label">
    							<xsl:text>Student Username</xsl:text>
    						</xsl:element>
    						<xsl:element name="identifier_string">
    							<xsl:value-of select="$UserName"/>
    						</xsl:element>
    					</xsl:element>
    					<xsl:element name="date">
    						<xsl:element name="type_label">
    							<xsl:text>Exam</xsl:text>
    						</xsl:element>
    						<xsl:element name="datetime">
    							<xsl:value-of select="$DateSubmitted"/>
    						</xsl:element>
    					</xsl:element>
    				</xsl:element>
    
    				<!-- Details about the assessment -->
    				<xsl:element name="assessment_result">
    					<xsl:attribute name="asi_title">
    						<xsl:value-of select="AssessmentName"/>
    					</xsl:attribute>
    					<xsl:attribute name="ident_ref">
    						<xsl:value-of select="AssessmentID"/>
    					</xsl:attribute>
    				</xsl:element>
    				<!-- End of populate the Context -->
    
    				<xsl:for-each select=".">
    					<xsl:variable name="elem">
    						<xsl:value-of select="name()"/>
    					</xsl:variable>
    					<xsl:variable name="elem_sub">
    						<xsl:value-of select="substring($elem,1,4)"/>
    					</xsl:variable>
    					<xsl:if test="$elem_sub='xSec_'">
    						<xsl:element name="section_result_title">
    							<xsl:attribute name="asi_title">
    								<xsl:value-of select="current()"/>
    							</xsl:attribute>
    						</xsl:element>
    					</xsl:if>
    				</xsl:for-each>
    			</result>
    		</qti_result_report>
    	</xsl:template>
    </xsl:stylesheet>
    No matter what I do I can't get this to work!! For some reason there is an issue here with matching the "/" root node.

    If I do <xsl:template match="AnswerLi st"> to start with it will fire off the template lower down the XSL but with NO values in it.... I can not figure out what position I am at in the code.

    If i do

    Code:
    <xsl:for-each select="child::node()">
    <xsl:for-each select="child::node()">
    <TEST />
    I will get the right amount of TEST's for the nodes in the AnswerList but I can not match them for some reason.

    As far as I can tell the XML is valid (Created in VS2005 according to a schema).

    I have had this before hbut was able to get a work-around looping through the code with "for-each"s but that is not appropriate in this case.

    I really need help here folks, as this project is already behind schedule and the customer is NOT happy! :S

    Thanks very much,

    Mark McGookin
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    If someone could do a transform on this in xmlnotepad or something and have a look at the results and tell me why it's not working I would really appreciate it!

    Cheers,

    Mark

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      Originally posted by markmcgookin
      If someone could do a transform on this in xmlnotepad or something and have a look at the results and tell me why it's not working I would really appreciate it!

      Cheers,

      Mark
      I figured this out... essentially XSLT HATES stuff with default namespace... so I changed my schema and XML file so I don't have a namespace in the XML doc and it's working (for now)

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        Originally posted by markmcgookin
        I figured this out... essentially XSLT HATES stuff with default namespace... so I changed my schema and XML file so I don't have a namespace in the XML doc and it's working (for now)
        Good of you to let us know it is working, Mark!

        Have a great week...

        Dököll

        Comment

        Working...