469,323 Members | 1,517 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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

markmcgookin
648 Expert 512MB
Hi,

I have the following XML

Expand|Select|Wrap|Line Numbers
  1. <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
  2.     <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved>
  3.     <UserName>Bob</UserName>
  4.     <AssessmentName>Name of Assessment</AssessmentName>
  5.     <AssessmentID>AssID</AssessmentID>
  6.     <Sec_1_1189068258258>TEXT IN HERE</Sec_1_1189068258258>
  7.     <Sec_2_1188555751625_MC0>1</Sec_2_1188555751625_MC0>
  8.     <Sec_2_1188555751625_MC1>2</Sec_2_1188555751625_MC1>
  9.     <Sec_2_1188555751625_MC2>3</Sec_2_1188555751625_MC2>
  10.     <Sec_2_1188555751625_MC3>4</Sec_2_1188555751625_MC3>
  11.     <xSec_Sec_1>Step 2 of 8 - What happened?</xSec_Sec_1>
  12.     <xSec_Sec_2>Step 4 of 8  Assessor feedback</xSec_Sec_2>
  13. </AnswerList>
  14.  
and the following XSL
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.     <!-- Declare the output doctype -->
  4.     <!--xsl:output method="xml" indent="yes"  doctype-system="ims_qtiresv1p2.dtd"></xsl:output -->
  5.     <xsl:template match="/">
  6.         <qti_result_report>
  7.             <result>
  8.                 <!-- Get the date that the assessment was submitted on -->
  9.                 <xsl:variable name="DateSubmitted">
  10.                     <xsl:value-of select="DateTimeLastSaved" />
  11.                 </xsl:variable>
  12.  
  13.                 <!-- Get the Username of the user submitting the document -->
  14.                 <xsl:variable name="UserName">
  15.                     <xsl:value-of select="UserName" />
  16.                 </xsl:variable>
  17.  
  18.                 <!-- Get the date that the assessment was submitted on -->
  19.                 <xsl:variable name="AssessmentName">
  20.                     <xsl:value-of select="AssessmentName" />
  21.                 </xsl:variable>
  22.  
  23.                 <!-- Populate the Context -->
  24.                 <xsl:element name="context">
  25.                     <xsl:element name="name">
  26.                         <xsl:value-of select="$UserName" />
  27.                     </xsl:element>
  28.                     <xsl:element name="generic_identifier">
  29.                         <xsl:element name="type_label">
  30.                             <xsl:text>Student Username</xsl:text>
  31.                         </xsl:element>
  32.                         <xsl:element name="identifier_string">
  33.                             <xsl:value-of select="$UserName"/>
  34.                         </xsl:element>
  35.                     </xsl:element>
  36.                     <xsl:element name="date">
  37.                         <xsl:element name="type_label">
  38.                             <xsl:text>Exam</xsl:text>
  39.                         </xsl:element>
  40.                         <xsl:element name="datetime">
  41.                             <xsl:value-of select="$DateSubmitted"/>
  42.                         </xsl:element>
  43.                     </xsl:element>
  44.                 </xsl:element>
  45.  
  46.                 <!-- Details about the assessment -->
  47.                 <xsl:element name="assessment_result">
  48.                     <xsl:attribute name="asi_title">
  49.                         <xsl:value-of select="AssessmentName"/>
  50.                     </xsl:attribute>
  51.                     <xsl:attribute name="ident_ref">
  52.                         <xsl:value-of select="AssessmentID"/>
  53.                     </xsl:attribute>
  54.                 </xsl:element>
  55.                 <!-- End of populate the Context -->
  56.  
  57.                 <xsl:for-each select=".">
  58.                     <xsl:variable name="elem">
  59.                         <xsl:value-of select="name()"/>
  60.                     </xsl:variable>
  61.                     <xsl:variable name="elem_sub">
  62.                         <xsl:value-of select="substring($elem,1,4)"/>
  63.                     </xsl:variable>
  64.                     <xsl:if test="$elem_sub='xSec_'">
  65.                         <xsl:element name="section_result_title">
  66.                             <xsl:attribute name="asi_title">
  67.                                 <xsl:value-of select="current()"/>
  68.                             </xsl:attribute>
  69.                         </xsl:element>
  70.                     </xsl:if>
  71.                 </xsl:for-each>
  72.             </result>
  73.         </qti_result_report>
  74.     </xsl:template>
  75. </xsl:stylesheet>
  76.  
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="AnswerList"> 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

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="child::node()">
  2. <xsl:for-each select="child::node()">
  3. <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
Dec 17 '07 #1
3 1802
markmcgookin
648 Expert 512MB
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
Dec 18 '07 #2
markmcgookin
648 Expert 512MB
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)
Dec 18 '07 #3
Dököll
2,364 Expert 2GB
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
Dec 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.