Click to See Complete Forum and Search --> : xslt question : i'm going stupid


willms_jay
05-12-2003, 11:47 AM
new to xslt, but i though i understood it.

Take this exml for example :



<?xml version="1.0" encoding="UTF-8"?>

<!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) by sis ICS-FORTH (ISL-ICS) -->

<!-- <!DOCTYPE lom SYSTEM "imsmd_v1p2p2.dtd"> -->

<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">

<general>

<title>

<langstring xml:lang="en"> Resumes and Interviews </langstring>

</title>

</lom>
---------------------------------------

Now, What I want to do is just print the title in between two <h1> </h1> brackets. eg. the xslt code that should do it imo

<xsl:stylesheet version = '1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/lom/general/title">

<h1>

<xsl:value-of select="langstring"/>

</h1>

</xsl:template>

</xsl:stylesheet>



But it doesn't work.... where is my logic incorrect? can anyone help me?

khalidali63
05-12-2003, 12:01 PM
You are missing end tag for general element


<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<general>
<title>
<langstring xml:lang="en"> Resumes and Interviews </langstring>
</title>
</general>
</lom>

willms_jay
05-12-2003, 12:08 PM
ya, sorry, that isn't the problem, I just forgot to put the </general> tag in when i pasted it.

Here is the whole XML file :
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) by sis ICS-FORTH (ISL-ICS) -->
<!-- <!DOCTYPE lom SYSTEM "imsmd_v1p2p2.dtd"> -->
<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<general>
<title>
<langstring xml:lang="en"> Resumes and Interviews </langstring>
</title>
<catalogentry>
<catalog>URI</catalog>
<entry>
<langstring xml:lang="en"> http://url.forthismovie.ca/resumes.mov</langstring>
</entry>
</catalogentry>
<catalogentry>
<catalog>POOL</catalog>
<entry>
<langstring xml:lang="en"> 000SamplePoolRefernece#2</langstring>
</entry>
</catalogentry>
<description>
<langstring xml:lang="en">Description: An interview with Lorna Court, Personnel Consultant, on how to impress employers with your resume. Court gives practical advice on what to put in your resume in order to secure an interview.</langstring>
</description>
</general>
<lifecycle>
<contribute>
<role>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Author</langstring>
</value>
</role>
<centity>
<vcard>

BEGIN: vCard

N: Heywood;Jeff

END: vCard

</vcard>
</centity>
</contribute>
<contribute>
<role>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none"> Publisher </langstring>
</value>
</role>
<centity>
<vcard>

BEGIN: vCard

ORG: Open School TV

ADR: Open School TV;555 Main Street;Vancouver;British Columbia;V5T 2U4

END: vCard

</vcard>
</centity>
<date>
<datetime>2001-02-01</datetime>
</date>
</contribute>
</lifecycle>
<metametadata>
<contribute>
<role>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Creator</langstring>
</value>
</role>
<centity>
<vcard>

BEGIN:vCard

Fisher;Sue

END:vCard

</vcard>
</centity>
</contribute>
<contribute>
<role>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Validator</langstring>
</value>
</role>
<centity>
<vcard>

BEGIN: vCard

ORG: POOL Project

END: vCard

</vcard>
</centity>
<date>
<datetime>2001-03-21</datetime>
</date>
</contribute>
<metadatascheme>CanCore 1.0</metadatascheme>
<metadatascheme>IEEELOM:1.0</metadatascheme>
<language>en</language>
</metametadata>
<technical>
<format>

video/quicktime

</format>
<location type="URI">

http://uri.forthismovie.inpoolrepository.ca/resume.mov

</location>
<duration>
<datetime>0000-00-00T00:03:11</datetime>
</duration>
</technical>
<educational>
<intendedenduserrole>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Learner</langstring>
</value>
</intendedenduserrole>
<intendedenduserrole>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Author</langstring>
</value>
</intendedenduserrole>
<intendedenduserrole>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Teacher</langstring>
</value>
</intendedenduserrole>
<context>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Secondary Education</langstring>
</value>
</context>
<context>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Higher Education</langstring>
</value>
</context>
<typicalagerange>
<langstring xml:lang="en">12-99</langstring>
</typicalagerange>
<language>en</language>
</educational>
<rights>
<cost>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">yes</langstring>
</value>
</cost>
<copyrightandotherrestrictions>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">yes</langstring>
</value>
</copyrightandotherrestrictions>
<description>
<langstring xml:lang="en"> Rights expiry: in perpetuity. Contact publisher for conditions of use.

</langstring>
</description>
</rights>
<classification>
<purpose>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Discipline</langstring>
</value>
</purpose>
<keyword>
<langstring xml:lang="en">Career planning </langstring>
</keyword>
</classification>
<classification>
<purpose>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">Idea</langstring>
</value>
</purpose>
<keyword>
<langstring xml:lang="en">job hunting</langstring>
</keyword>
<keyword>
<langstring xml:lang="en">resumes</langstring>
</keyword>
<keyword>
<langstring xml:lang="en">job applications</langstring>
</keyword>
</classification>
<classification>
<purpose>
<source>
<langstring xml:lang="x-none">LOMv1.0</langstring>
</source>
<value>
<langstring xml:lang="x-none">PedagogicType</langstring>
</value>
</purpose>
<taxonpath>
<source>
<langstring xml:lang="en">CanCore</langstring>
</source>
<taxon>
<entry>
<langstring xml:lang="en">Component</langstring>
</entry>
</taxon>
</taxonpath>
</classification>
</lom>


And the ONLY thing I'd like to select is the title

Resume and Interviews and put in between <h1> </h1>

/general/title/langstring

can anyone help, I'm sure this is tupidly simple, I guess I just don't understand how these path's work.

..jordan

khalidali63
05-12-2003, 12:16 PM
let me see,because I could get interviews and resume as the result..But looking at your xml it might change things..:D

willms_jay
05-12-2003, 12:18 PM
just to clarify, I would like to get the value between these tags :

<title>
<langstring xml:lang="en"> Resumes and Interviews </langstring>
</title>

-- > "Resumes and Interviews"

khalidali63
05-12-2003, 12:34 PM
Here is the xsl code that will get the required value from xml file for you


<?xml version='1.0'?>
<xsl:stylesheet
version = "1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="lom">
<h1>
<xsl:value-of select="general/title/langstring"/>
</h1>
</xsl:template>
</xsl:stylesheet>

willms_jay
05-12-2003, 01:19 PM
thanks, although, it still doesn't seem to work.

this is the result i get :



Human Resource ManagementURI http://www.algonquincollege.com/distance/certfs.htmlPOOL 000SamplePoolRefernece#This course deals with personnel functions, including concepts, principles and practices; techniques of personnel administration (roles, staffing, human resources, employee development and incentives for effective performance); and management's responsibility in personnel administration.MGT2310LOMv1.0Publisher

BEGIN: vCard

ORG: Algonquin College

END: vCard

2001-02-01LOMv1.0Creator

BEGIN:vCard

Fisher;Sue

END:vCard

LOMv1.0Validator

BEGIN: vCard

ORG: POOL Project

END: vCard

2001-02-01CanCore 1.0IEEELOM:1.0entext/htm

http://www.algonquincollege.com/distance/certfs.html

Group Work is required for computer conferencingLOMv1.0LearnerLOMv1.0University Undergraduate18-99enLOMv1.0yesLOMv1.0yesRegistration $332.85 Can. Contact Carole Smith, csmith@algonquinc.on.caLOMv1.0DisciplineEricHuman ResourcesManagementLOMv1.0PedagogicTypeCanCoreCourse


Again, your logic seems sound, but it just doesn't seem to work. Have you gotten it to work? I use XMLspy, and it isn't working in there!

It seems to be printing out all values contained within any tag named 'langstring' rather than the one we want.



I'm so confused!

..jordan willms

khalidali63
05-12-2003, 02:05 PM
Originally posted by willms_jay
thanks, although, it still doesn't seem to work.

.......

I have it working,the error must be in rest of the xslt code.

Here is the link where I have it working.

http://68.145.35.86/temp/willms_jay/wjay.xml

willms_jay
05-12-2003, 02:53 PM
YES!

Here's the thing I don't understand.

It worked when i did the following like you :



<lom>



but it doesn't work when it is like this :



<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">



WHY?

Also, I am recieving these files as is, so how am I going to edit them to remove all the attributes after the lom tag?

Also.

Why is this even causing a problem in the first place!??!

..jordan

khalidali63
05-12-2003, 03:08 PM
That probably has to do something specifically prprietery crap by MS,I hope I am wrong,but I don't see any reason why it would not work.

willms_jay
05-12-2003, 03:09 PM
i'm not using ms though, I am using xmlspy.

But why did you remove it in the firstplace, were you getting the same errors?

..jordan

khalidali63
05-12-2003, 03:15 PM
I removed so that I knew I was not pointing to any MS specific schema..

This is the line that is causing problem

xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2"

I'll try to see what exactly it could have caused.

willms_jay
05-12-2003, 03:23 PM
it's actually not MS schema.

It stands for

IMS -- nothing to do with microsoft.

man, i am so confused. thank you for helping. any additional help will be greatly appretiated.

..jordan willms

khalidali63
05-12-2003, 03:38 PM
I used wrong words,
I meant it points to a proprietery resource,for which I am afraid I have no Idea what could be wrong.I could help as long as the code is w3c standard,,,,

willms_jay
05-12-2003, 04:18 PM
in the end i had to do this :


<?xml version="1.0"?>
<xsl:stylesheet xmlns:cancore="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="cancore:lom">
<xsl:apply-templates select="cancore:general" />
</xsl:template>

<xsl:template match="cancore:general">
<xsl:apply-templates select="cancore:title" />
</xsl:template>

<xsl:template match="cancore:title">
<xsl:apply-templates select="cancore:langstring" />
</xsl:template>

</xsl:stylesheet>



because of some namespace bull****.

what sucks, is how I can't do a

<xsl:value-of select="canore:general/title/langstring" />

for some reason it makes me do it like this template level by template level.

..confuseing.

..jordan

sheila
05-12-2003, 05:46 PM
Does this work?

<xsl:value-of select="cancore:general/cancore:title/cancore:langstring" />

khalidali63
05-12-2003, 05:53 PM
This is all proprietery crap,they must have provided you with some docs on this..otherwise its really stupid to code with guess work.
Particularly xsl,because it usually won't give you the error,it wouls just spit out all the document..

willms_jay
05-13-2003, 12:48 PM
not really, after doing some reseach, it all had to do with namespaces and **** :

to quota a wrox book :

"If an element you want to select or match is in a namespace, you have to use a name test that uses the prefix associated with that namespace within the stylesheet."

Thanks for all the help guys!

..jordan