473,466 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

markmcgookin
648 Recognized Expert Contributor
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 2171
markmcgookin
648 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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

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

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
2
by: pintihar | last post by:
I am trying to map external xml documents to a class in dotnet. The problem is that the elements of the input xml will have different names than the properties of the class. How do I create the...
0
by: Leira | last post by:
Hi, I have a problem with grouping. My source XML has <record> elements that have a @name and a @group attribute. It looks something like this: <root> <result> <record name="test1"...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.