473,698 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT and XSD

I posted this on topxml.com and nobody has responded so I was hoping
somebody could help me here. I am following some tutorials in VS.NET.
I created a XSD schema file and then from there created an XML file.
Everything works okay and my data is validated against the schema. Now
when I try to display my xml using xsl it won't work unless I get rid
of the xmlns property of the xml file that points to my schema. Why
would I need to get rid of that property for the xml to display?
Jul 20 '05 #1
13 6650
This is a very FAQ. Read for example:

None of my XPath select statements will work going against an XML file with
a default namespace. Help!
by Mark Bosley

at: http://www.topxml.com/people/bosley/defaultns.asp

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Mark Constant" <co*******@mi x-net.net> wrote in message
news:ce******** *************** ***@posting.goo gle.com...
I posted this on topxml.com and nobody has responded so I was hoping
somebody could help me here. I am following some tutorials in VS.NET.
I created a XSD schema file and then from there created an XML file.
Everything works okay and my data is validated against the schema. Now
when I try to display my xml using xsl it won't work unless I get rid
of the xmlns property of the xml file that points to my schema. Why
would I need to get rid of that property for the xml to display?

Jul 20 '05 #2
FC
I have a slightly different problem instead and I can't find the way out.
I am not using an explicit default namespace, but I am hitting the famous
problem of the unwanted namespace declarations inside result tree elements:

Take the samples at TopXml and change them slightly:
<?xml version="1.0" encoding="UTF-8"?>

<requestHierarc hySelectResult resultName=""
xmlns:cs="http://www.customsolid s.com">

<request>

<created_dt>0 5/05/2000 00:00:00</created_dt>

<created_tm>0 1/01/1900 14:02:46</created_tm>

<cs:request_i d>

<my_value>12345 </my_value>

</cs:request_id>

</request>

</requestHierarch ySelectResult>

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

<xsl:styleshe et

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

xmlns:cs="http://www.customsolid s.com"

version="1.0"

exclude-result-prefixes="cs">

<xsl:output indent="yes"/>

<xsl:template match="/">

<out>

<xsl:apply-templates select="//cs:request_id/my_value"/>

</out>

</xsl:template>

<xsl:template match="*|@*|nod e()"/>

<xsl:template match="my_value ">

<xsl:copy>

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

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

The result is:

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

<out>

<my_value xmlns:cs="http://www.customsolid s.com">12345</my_value>

</out>

My question is, how to get rid of the xmlns:cs namespace declararion inside
<my_value>?

Bye,

Flavio

Jul 20 '05 #3

"FC" <fl****@tin.i t> wrote in message
news:ex******** *************** @news2.tin.it.. .
I have a slightly different problem instead and I can't find the way out.
I am not using an explicit default namespace, but I am hitting the famous
problem of the unwanted namespace declarations inside result tree elements:
Take the samples at TopXml and change them slightly:
<?xml version="1.0" encoding="UTF-8"?>

<requestHierarc hySelectResult resultName=""
xmlns:cs="http://www.customsolid s.com">

<request>

<created_dt>0 5/05/2000 00:00:00</created_dt>

<created_tm>0 1/01/1900 14:02:46</created_tm>

<cs:request_i d>

<my_value>12345 </my_value>

</cs:request_id>

</request>

</requestHierarch ySelectResult>

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

<xsl:styleshe et

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

xmlns:cs="http://www.customsolid s.com"

version="1.0"

exclude-result-prefixes="cs">

<xsl:output indent="yes"/>

<xsl:template match="/">

<out>

<xsl:apply-templates select="//cs:request_id/my_value"/>

</out>

</xsl:template>

<xsl:template match="*|@*|nod e()"/>

<xsl:template match="my_value ">

<xsl:copy>

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

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

The result is:

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

<out>

<my_value xmlns:cs="http://www.customsolid s.com">12345</my_value>

</out>

My question is, how to get rid of the xmlns:cs namespace declararion inside <my_value>?

The short answer is: You get what you specified -- copying an element copies
all its namespace nodes. This element is not a literal-result-element, so
exclude-result-prefixes does not apply to it.

Also, the meaning of copying is to copy the node as is with no change. This
means that all namespace nodes of the node must be copied.

To achieve what you want use:

<xsl:template match="my_value ">
<xsl:element name="{name()}" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #4
FC

"Dimitre Novatchev" <dn********@yah oo.com> wrote in message
news:bn******** *****@ID-152440.news.uni-berlin.de...

"FC" <fl****@tin.i t> wrote in message
news:ex******** *************** @news2.tin.it.. .
My question is, how to get rid of the xmlns:cs namespace declararion inside
<my_value>?

The short answer is: You get what you specified -- copying an element

copies all its namespace nodes. This element is not a literal-result-element, so
exclude-result-prefixes does not apply to it.

Also, the meaning of copying is to copy the node as is with no change. This means that all namespace nodes of the node must be copied.

To achieve what you want use:

<xsl:template match="my_value ">
<xsl:element name="{name()}" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Thanks Dimitre!
What makes me feel so sad is that I've been using Xpath inline expressions
all over my transformations and my brain went blank in this case.
I mean, it's so obvious I can solve it by replacing each and every element
with its cleansed counterpart by means of name().
And I can't even take a vacation, it's still 9 months ahead...

Bye,
Flavio

Jul 20 '05 #5
"Dimitre Novatchev" <dn********@yah oo.com> wrote in message news:<bn******* ******@ID-152440.news.uni-berlin.de>...
This is a very FAQ. Read for example:

None of my XPath select statements will work going against an XML file with
a default namespace. Help!
by Mark Bosley

at: http://www.topxml.com/people/bosley/defaultns.asp

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Thank you for your help. I got it so the elements display on a screen
but now the HTML doesn't work. Here is what I have so far. Sorry if
this looks ugly but I am new to this.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebs ite">
<xsl:template match="lc">
<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Ente rtainment/GameList">
<tr>
<th colspan="2"><xs l:value-of select="lc:Titl e"/></th>
</tr>
<tr>
<td>
<xsl:element name="lc:IMG">
<xsl:attribut e name="lc:SRC">
<xsl:value-of select="lc:Imag e"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:valu e-of select="lc:Desc ription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #6
>
Thank you for your help. I got it so the elements display on a screen
but now the HTML doesn't work. Here is what I have so far. Sorry if
this looks ugly but I am new to this.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebs ite">
<xsl:template match="lc">
<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Ente rtainment/GameList">
<tr>
<th colspan="2"><xs l:value-of select="lc:Titl e"/></th>
</tr>
<tr>
<td>
<xsl:element name="lc:IMG">
<xsl:attribut e name="lc:SRC">
<xsl:value-of select="lc:Imag e"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:valu e-of select="lc:Desc ription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Unless somebody is a clairevoyant (and also knows xslt) you're probably not
going to get any help.

Where is your source xml document?

What is the result that you want to get?

What output do you get instead?

What are the essential properties of the transformation?

What does it mean "the HTML doesn't work" ?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #7
"Dimitre Novatchev" <dn********@yah oo.com> wrote in message news:<bn******* ******@ID-152440.news.uni-berlin.de>...
Unless somebody is a clairevoyant (and also knows xslt) you're probably not
going to get any help.

Where is your source xml document?

What is the result that you want to get?

What output do you get instead?

What are the essential properties of the transformation?

What does it mean "the HTML doesn't work" ?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Sorry I didn't include everything. Anyways all I am getting is a
string that reads 1ps2slycooperAW ittygamethatisf unforeberybodyi mages\SlyCooper .jpg
on a html page. When I say "the HTML doesn't work" I mean that the
tables and headings aren't appearing on the page so that the page
doesn't comes out formatted. All I want is a clean list of a picture,
title, and description on a HTML page. I am trying to get a very basic
..xml file working and from there I will build upon it. Below are my
files.

Here is my games.xsd file
<?xml version="1.0" encoding="iso-8859-1" ?>
<xs:schema id="Games" targetNamespace ="http://mark/DevelopmentWebs ite"
elementFormDefa ult="qualified" xmlns="http://mark/DevelopmentWebs ite"
xmlns:mstns="ht tp://mark/DevelopmentWebs ite"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Entertain ment">
<xs:complexType >
<xs:sequence>
<xs:element name="GameList" >
<xs:complexType >
<xs:sequence>
<xs:element name="ID" type="xs:positi veInteger" />
<xs:element name="Console" type="xs:string " />
<xs:element name="Title" type="xs:string " />
<xs:element name="Descripti on" type="xs:string " />
<xs:element name="Image" type="xs:string " />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

This is my games.xml file
<?xml version="1.0" encoding="utf-8" ?>
<Entertainmen t xmlns="http://mark/DevelopmentWebs ite">
<GameList>
<ID>1</ID>
<Console>PS2</Console>
<Title>Sly Cooper</Title>
<Description> A fun game for everybody</Description>
<Image>images\S lyCooper.jpg</Image>
</GameList>
</Entertainment>

This is my games.xslt file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebs ite">
<xsl:template match="lc">
<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Ente rtainment/GameList">
<tr>
<th colspan="2"><xs l:value-of select="lc:Titl e"/></th>
</tr>
<tr>
<td>
<xsl:element name="lc:IMG">
<xsl:attribut e name="lc:SRC">
<xsl:value-of select="lc:Imag e"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:valu e-of select="lc:Desc ription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #8
> This is my games.xml file
<?xml version="1.0" encoding="utf-8" ?>
<Entertainmen t xmlns="http://mark/DevelopmentWebs ite">
<GameList>
<ID>1</ID>
<Console>PS2</Console>
<Title>Sly Cooper</Title>
<Description> A fun game for everybody</Description>
<Image>images\S lyCooper.jpg</Image>
</GameList>
</Entertainment>

This is my games.xslt file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebs ite">
<xsl:template match="lc">
There is no element named "lc" in your source.xml -- this template is never
instantiated.

This completely explains what you get (this is the result of the XSLT
built-in templates) -- just the concatenation of all text nodes.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Ente rtainment/GameList">
<tr>
<th colspan="2"><xs l:value-of select="lc:Titl e"/></th>
</tr>
<tr>
<td>
<xsl:element name="lc:IMG">
<xsl:attribut e name="lc:SRC">
<xsl:value-of select="lc:Imag e"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:valu e-of select="lc:Desc ription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Jul 20 '05 #9
"Dimitre Novatchev" <dn********@yah oo.com> wrote in message news:<bn******* ******@ID-152440.news.uni-berlin.de>...
This is my games.xml file
<?xml version="1.0" encoding="utf-8" ?>
<Entertainmen t xmlns="http://mark/DevelopmentWebs ite">
<GameList>
<ID>1</ID>
<Console>PS2</Console>
<Title>Sly Cooper</Title>
<Description> A fun game for everybody</Description>
<Image>images\S lyCooper.jpg</Image>
</GameList>
</Entertainment>

This is my games.xslt file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:lc="http://mark/DevelopmentWebs ite">
<xsl:template match="lc">


There is no element named "lc" in your source.xml -- this template is never
instantiated.

This completely explains what you get (this is the result of the XSLT
built-in templates) -- just the concatenation of all text nodes.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

<h2>My Game Collection</h2>
<table border="1">
<xsl:for-each select="lc:Ente rtainment/GameList">
<tr>
<th colspan="2"><xs l:value-of select="lc:Titl e"/></th>
</tr>
<tr>
<td>
<xsl:element name="lc:IMG">
<xsl:attribut e name="lc:SRC">
<xsl:value-of select="lc:Imag e"/>
</xsl:attribute>
</xsl:element>
</td>
<td><xsl:valu e-of select="lc:Desc ription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>


I took out the <xsl:template match="lc"> in my games.xslt file and
changed it back to <xsl:template match="/">. In my games.xml file I
changed
xmlns="http://mark/DevelopmentWebs ite" to
xmlns:lc="http://mark/DevelopmentWebs ite" to match the prefix in my
..xslt file. This causes my heading to appear from my HTML but once
again I go back to getting nothing from my xml file. I have read many
many tutorials on the internet and I still don't seem to have a clear
idea of what I am missing.
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3903
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a "crumb-trail" of links. I'm transforming the XML with XSLT through Saxon. The nav menu and "crumb-trail" show the user where they are within the site and is made by reflecting the XML tree structure. My problem now is that when I want to generate...
2
2791
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now wondering if I am better of learning XQuery instead? Any thought and opinions would be appreciated. Cheers - Tom. The Architect: "Hope, it is the quintessential human delusion,
1
3601
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by version 2 of XSLT processor based on some condition. Q) How and where shall I write logic or import desirable XSLT on the Fly ? Q) When we call AAA.XSLT then it will be processed by XSLT Processor 1
0
2353
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
3
2195
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about the development environment or recommend me some other that you know. XML IDE's - http://xslt-process.sourceforge.net - http://www.mentattech.com/themes/mentat/alchemist/index.html Regards,
7
2858
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
3
3090
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION> <OPTION>3<OPTION> </FIELD>
1
2415
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
12
11592
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I don't want to have to use some external program or script to parse the csv first if possible
2
22771
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
0
8673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7716
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.