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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to XSL and names spaces 1

Status
Not open for further replies.

scheduleboy

Programmer
Jan 13, 2005
4
GB
Hi,

I'm have an XML document that models an invoice from our company.
I also have developed a XSL file to transform the XML and display it nicely formatted in a web browser.
The above works well and I'm very happy with it.

I now want to include our company's URL as a namespace, I declare it as in the root node of my XML document, as per a tutorial I've read - it therefore becomes the default namespace? But now my XSL conversion just gives the XHMTL output with no data.
So what do I need to do to my XSL file to allow it to process the XML with the namespace?

Examples greatly appreciated...

Thanks

Jim


 
Hi,
I am trying to build an XSLT Generator. The input to this XSLT Generator is an XSD (say, source.xsd) AND the output format is Target.xsd. The objective is to generate an XSL.

Where do I start? Any design guidelines, best practices that you can suggest.

Is there any source code available anywhere?

Appreciate your help.

thanks
Suki
 
I usually direct everyone new to XML, and/or the technologies it uses, to W3 Schools...
They have fast little tutorials you can read over quickly and try yourself...
I learned most of the stuff I know in a day or 2 with the help or W3 Schools... (and Google :p)

So...
Here is the link: Read over the areas of interest, then post questions about specific things you don't understand and/or you can't get to work...

Areas specific to this post include:
XML
XSL
XSD

Hope This Helps ;-)
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Hi Josh,

Cheers for the advise, I have already be there and gone through then XML & XSL tutorials, as well as those at - great site BTW.
None of the tutorials was of much help - the XML one showed how to create namespaces, the XSL showed how o navigate an XML document - but only for XML docs with no declared namespace.

Please could you give a very simple example of an XML doc using a namespace and then a equally as simple XSL document transforming the XML doc.

Thanks in advance

Jim
 
OK, let's start with what you have, and what you are trying to do (specifically)

such as I have this:
Code:
<xx>
  <yy>
    <aa>1</aa><bb>2</bb><cc>3</cc>
  </yy>
  <yy>
    <aa>4</aa><bb>5</bb><cc>6</cc>
  </yy>
  <yy>
    <aa>7</aa><bb>8</bb><cc>9</cc>
  </yy>
</xx>

I want this:
Code:
<html>
<body>
<table>
  <tr>
    <td>1</td><td>2</td><td>3</td>
  </tr>
  <tr>
    <td>4</td><td>5</td><td>6</td>
  </tr>
  <tr>
    <td>7</td><td>8</td><td>9</td>
  </tr>
</table>
</body>
</html>

That makes it easier to understand EXACTLY what you want/need to do...
Then we can produce an example for you...

Thanks,
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
You can figure out most problems from the w3c specs, although they can be a bit hard to read:


Basically, the XSLT engine needs a fully qualified name to reference a node. This means to reference any node in XSLT that uses a namespace, you need to have a refence to that namespace in the XSLT and that namespace must use a prefix whether it refers to the default namespace or not.

Here's a basic transform:

XML:
Code:
<?xml version="1.0"?>
<test xmlns="http:\\somewhere">
	<anode>some data</anode>
</test>

XSLT:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:someprefix="http:\\somewhere" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
	<xsl:template match="/">
		<test>
			<xsl:value-of select="someprefix:test/someprefix:anode"/>
		</test>
	</xsl:template>
</xsl:stylesheet>

Hope that helps, took me a while to figure out to begin with.

Jon
 
Hi Jon,

That was great - thanks.
My problem was that in my XSL template, I was only using the namespace prefix once in the path e.g

someprefix:test/anode

once I prefixed each node in the path with the prefix e.g.

someprefix:test/someprefix:anode

it worked like a charm!!

Thanks

Jim


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top