• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use different XSL files on the same XML doc

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I use different XSL files on one XML document?

I have one XML file which I want to display in different ways. Therefore I have made i.e. 3 XSL files.

But I have this problem that the only way I know to use the XSL file is to include it in the top of the XML file, like:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="info.xsl"?>
...

But in this way I have to make one XML file for each XSL file.

Is it possible to include the XML file in the XSL file instead or what are the solution?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you are doing it now, you are relying on the browser to do the transformation for you. If you don't have anything on your server side that can do Java processing, then I think your only option is to produce three almost-identical versions of the XML file.

However if you have something at the server side that can dynamically insert that processing instruction, or that can actually do the transformation, then do that. But I won't get into explaining how unless there is a possibility the information might be useful.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don�t have the possibilty do it in java. I just hoped it could be done in pure XML and XSLT!
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the stylesheet "hard coded" in an XML file you can not change?

OK, so you can not do Java. Can you run Java programs?

If you could do this from a "command line", would that work? (See Xalan examples at apache.org).

Guy
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hope this will help you.. we can transform XML into HTML using xsl in java script. ( see sample code below). by using this you can display same XML with three different xsl files.

<html>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("sample.xml")

// Load the XSL file 1
var xsl1 = new ActiveXObject("Microsoft.XMLDOM")
xsl1.async = false
xsl1.load("xslfile1.xsl")

// Load the XSL file 2
var xsl2 = new ActiveXObject("Microsoft.XMLDOM")
xsl2.async = false
xsl2.load("xslfile2.xsl")

// Transform
document.write(xml.transformNode(xsl1))
document.write(xml.transformNode(xsl2))
</script>

</body>
</html>

Nuthan
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a solution which is made in pure HTML/XML/XSL. The solution with loading the XML file from Javascript is working fine. Thank you.

I am used to code in JAVA where there is no constraints at all. I can see I am facing some new challenges now:

On the website I am displaying the three latest news from a XML document. Every news-story has its own ID (I use the RSS format). In my XSL I display every news title as a link, that will point to a new site and show only that news-story ( http://www.myDomain.com/news?newsID=85 ).

Is that possible to do in pure HTML/XML/XSL?

How Can I get the newsID parameter on another site and how can I send this parameter to my XSL file, so it can be used in a XPath expression?
[ July 11, 2006: Message edited by: Jeppe Fjord ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic