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

Header Change Broke XSLT 1

Status
Not open for further replies.

stoolpigeon

Programmer
Aug 1, 2001
309
0
0
US
I have an XML file that I transform into a fixed width text file using XSLT and the MSXML 3.0 parser. Recently the XML file was changed and I've been rewriting my XSL file. A schema was added and for some reason my XSL doesn't work any more unless I make a change to the XML file. Right now the file comes to me like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Data xmlns="[URL unfurl="true"]http://www.healthoutsource.com/JdaSchema/XMLAOPlacement1.xsd"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
	<Vendor>
And my XSL file starts out:
Code:
<?xml version="1.0" ?>
<xsl:stylesheet
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="[URL unfurl="true"]http://mycompany.com/mynamespace"[/URL]
version="1.0">
I've got some VB scripts stuff in there and what not then I get to my first template and it runs like this:
Code:
<xsl:template match="/">
	<xsl:for-each select="/Data/Vendor[Confirmed_Id=$repidin or Confirmed_Id=$repidin2]">
The root matches up but then it never drops into the for each because apparently /Data/Vendor does not match. If I leave the xsl the way it is but change the data element in the XML file to this:
Code:
<Data xmlns:a="[URL unfurl="true"]http://www.healthoutsource.com/JdaSchema/XMLAOPlacement1.xsd"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
Then everything works and the file gets transformed. If I have to I guess I can edit the XML file with my code before I load it up into DOM but I think my problem is maybe I need to do something in XSL to get the namespace to mach up-- but I can't figure out how.

Any help -- or a point in the right direction to some resources would be very much appreciated.
 
You need to define your schema (that is in the xml file) in your xslt with a prefix. Then anytime you use XPath for the xml file, each node needs to include the prefix.

If I defined xmlns:user=" then my XPath should be select="/user:Data/user:Vendor[user:Confirmed_Id=$repidin or user:Confirmed_Id=$repidin2]"

Something along those lines. When you define your own namespace in your XML, you need to also refer to that namespace in the XSLT.

-jay
 
Thanks. I tried something along those lines but I don't think I ever got the whole thing quite right. I just ran it through and it looks good.

It looks like once I'm into the right name space- then the stuff below defaults to that -- because I added the namespace part to that select but not to the stuff below- and the stuff below came through also.

I'll keep reading up on it later but at least now I can get the file finished and then go back and figure out the exact details.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top