Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with XML Schemas and XSLTs 1

Status
Not open for further replies.

JonBroadley

Programmer
Nov 22, 2006
2
GB
I'm fairly new to XML and after battling through a few problems I have finally reached one that I am completely stuck on. I am trying to read in a SCORM manifest file, I have created a manifest using reload tools ( then updated the xsd schemas to the latest version from the imsglobal ( servers to clear some code warnings.

I have now created an xsl file to extract the data to create a treeview in ASP.Net2 the file works up to a point. If I cut down the initial manifest line from

<manifest
identifier="imsmdv1p2p1_manifest"
xmlns=" xmlns:imsmd=" xmlns:xsi=" xsi:schemaLocation=" imscp_v1p1.xsd
imsmd_v1p2p4.xsd"
version="IMS CP 1.1.3">

to

<manifest
identifier="imsmdv1p2p1_manifest"
version="IMS CP 1.1.3">

I can read and display the file in a tree view. If I leave it as is then all I get is my root node.

The xsl file is as follows:-

<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl=" xmlns:xsi=" xmlns:xsd=" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>
<xsl:strip-space elements="*"/>
<xsl:eek:utput method="xml"
omit-xml-declaration="yes"
indent="yes"
standalone="yes" />

<xsl:template match="/">
<xsl:element name="Lesson">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="//item">

<xsl:element name="item">
<xsl:attribute name="identifierref">
<xsl:value-of select="@identifierref"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

</xsl:stylesheet>

The code can be seen at
If anyone has any suggestions about what the problem could be then I would be really grateful.

Jon
 
You need to take into account of the default namespace in the xml document. This is the minimal fix in the xsl source file. The prefix is of course arbitrarily chosen as long as consistency is observed.
[tt]
<xsl:stylesheet
version="1.0"
xmlns:xsl=" xmlns:xsi=" xmlns:xsd=" [blue]xmlns:imscp="[/blue]
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>
<xsl:strip-space elements="*"/>
<xsl:eek:utput method="xml"
omit-xml-declaration="yes"
indent="yes"
standalone="yes" />

<xsl:template match="/">
<xsl:element name="Lesson">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="//[blue]imscp:[/blue]item">

<xsl:element name="item">
<xsl:attribute name="identifierref">
<xsl:value-of select="@identifierref"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

</xsl:stylesheet>
[/tt]
ps: those xsi and xsd declared in the xsl document are not usual. I do not touch it and give full benefit of the doubt. msxsl as ms extension might be used with something else not shown, so I do not touch it neither.
 
Thank you so much :)

That works a treat, I guess I need to spend more time reading up on namespaces.

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top