E aí Marcelo, tudo em cima?
<xsl:apply-templates> doesn't work because you have no templates to apply! And
even if you example work (besides the apply-template) it's not good writen.
Instead of a for-each, place the code in template that take care of you
catalog/cd, and write another one to take care of your teste.xml/cd. Then yoy
have templates to apply to. Look at the code below.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:apply-templates select="catalog/cd"/>
<xsl:apply-templates select="document('teste.xml')/cd"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:template>
<xsl:template match="cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Um abraço cá deste lado...
Quoting Marcelo <marcelochyna(_at_)yahoo(_dot_)com(_dot_)br>:
Hi Again! I did what you said but I can't make it
work. What am I doing wrong?
Here is my files:
cdcatalog.xsl
****************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="document('teste.xml')"/>
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
****************************************************
cdcatalog.xml
****************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
****************************************************
teste.xml
****************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
****************************************************
transformador.htlm
****************************************************
<html>
<body>
<script type="text/javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load("cdcatalog.xml");
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("cdcatalog.xsl");
// Transform
document.write(xml.transformNode(xsl));
</script>
</body>
</html>
****************************************************
--- JBryant(_at_)s-s-t(_dot_)com escreveu:
Make that:
<xsl:apply-templates
select="document('otherDocument.xml')"/>
I was just looking at one of my own stylesheets that
merges two documents
(today's problem to solve) and noticed that I had
forgotten the quotation
marks in the message I sent to the list.
Sorry about the extra traffic.
Jay Bryant
Bryant Communication Services
JBryant(_at_)s-s-t(_dot_)com
12/09/2004 05:44 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject
Re: [xsl] Convert 2 xml with 1 xsl file
I can't speak to the Java part of it, but the
document function can solve
the convert two (or n) files from a single
stylesheet problem. The
following instruction pulls in the content of
another document and
processes it:
<xsl:apply-templates
select="document(otherDocument)"/>
Jay Bryant
Bryant Communication Services
Marcelo <marcelochyna(_at_)yahoo(_dot_)com(_dot_)br>
12/09/2004 08:30 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc
Subject
[xsl] Convert 2 xml with 1 xsl file
Hi! May anybody help me? I need to convert 2 xml
with
1 xsl file to a XHTML file. How do I do that?
Besides that. Does anybody knows Java? Because I
need
to do this convertion within it.
My code converts 1 xml with 1 xsl file. But how can
I
do with 2 xml)
Thanks.
Marcelo.
This is my code:
***************************************************
public static void xsl(
String xml1,
String xml2,
String outFilename,
String xslFilename)
{
try {
//
Create transformer
factory
TransformerFactory
factory =
TransformerFactory.newInstance();
//
Use the factory to
create a template containing
the xsl file
Templates template =
factory.newTemplates(
new StreamSource(new
FileInputStream(xslFilename)));
//
Use the template to
create a transformer
Transformer xformer =
template.newTransformer();
InputStream in = new
URL(xml1).openStream();
//
StringBuffer s = new
StringBuffer();
System.out.println(in.toString());
Source source = new
StreamSource(in);
//Source source = new
StreamSource(new
FileInputStream(inFilename));
Result result = new
StreamResult(new
FileOutputStream(outFilename));
//
Apply the xsl file to
the source file and write
the result to the output file
xformer.transform(source,
result);
} catch
(FileNotFoundException e) {
System.out.println("FileNotFoundException ");
e.printStackTrace();
} catch
(TransformerConfigurationException e) {
System.out.println("TransformerConfigurationException
");
e.printStackTrace();
//
An error occurred in
the XSL file
} catch
(TransformerException e) {
System.out.println("TransformerException ");
//
An error occurred
while applying the XSL file
//
Get location of error
in input file
SourceLocator locator =
e.getLocator();
int
col =
locator.getColumnNumber();
int
line =
locator.getLineNumber();
String publicId =
locator.getPublicId();
String systemId =
locator.getSystemId();
e.printStackTrace();
} catch
(MalformedURLException e) {
//
TODO Auto-generated
catch block
e.printStackTrace();
=== message truncated ===
__________________________________________________
Converse com seus amigos em tempo real com o Yahoo! Messenger
http://br.download.yahoo.com/messenger/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--