xslt and xml problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi to all,

I have a xml file with labels and data.

Im trying to mix both files to generate someting like:

Label A : data of node a
Label B : data of node b
Label C : data of node c

My main problem its that the only thing that i know is that the number of
node labels is equal to the nodes of data.

<MYDataSet>
<Table1>
<A>Label A</A>
<B>Label B</B>
<C>Label C</C>
<D>Label D</D>
</Table1>
<Table3>
<A>Data of Node A</A>
<B>Data of node B</B>
<C>data of node c</C>
<D>data of node d</D>
</Table3>
</MYDataSet>

For other hand i have this xslt sheet:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/MYDataSet">
<table>
<tr>
<td>
<h2>Detalle de electricidad</h2>
</td>
</tr>
<xsl:apply-templates select="Table1"/>
</table>
</xsl:template>
<xsl:template match="Table1/*">
<tr>
<td><xsl:value-of select="."></xsl:value-of></td>
<td><xsl:value-of
select="../../Table3/ancestor::name/."></xsl:value-of></td>
</tr>
</xsl:template>
</xsl:stylesheet>
 
Here is a sample, that you can "pick off" information from another node(set)
in the same xml.

The "current" call is what I think you're after.




***************** START XML **********************


<?xml version="1.0" encoding="iso-8859-1" ?>

<root>
<publisher>
<books>
<book>
<title>J'aime la musique de Celine Dion Beaucoup Beaucoup</title>
<ISBN>044178386</ISBN>
<author-ref ref="rh"/>
<sold>2300000</sold>
</book>

<book>
<title>Estce que tu achete tes chasseurs au Monoprix?</title>
<ISBN>0345328116 </ISBN>
<author-ref ref="rh"/>
<author-ref ref="jldr"/>
<sold>80000</sold>
</book>

</books>



<authors>

<author id="rh">
<first_name>Robert</first_name>
<last_name>Heinlein</last_name>
</author>

<author id="jldr">
<first_name>Judy</first_name>
<last_name>Smith</last_name>
</author>

<author id="nwo">
<first_name>Nellie</first_name>
<last_name>Olsen</last_name>
</author>


</authors>
</publisher>

</root>






***************** ENDXML **********************

***************** START XSL**********************



<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">




<xsl:template match="/">

<table border='1'>

<xsl:apply-templates select="root/publisher/authors/author">
<xsl:sort select="last_name"/>
</xsl:apply-templates>

</table>

</xsl:template>


<xsl:template match="author">
<tr>


<td>
<xsl:value-of select="last_name"/>, <xsl:value-of select="first_name"/>
</td>

<td>
<xsl:value-of
select="count(/root/publisher/books/book[author-ref/@ref=current()/@id])"/>
</td>

</tr>

</xsl:template>

</xsl:stylesheet>






***************** END XSL**********************




************ START VBS FILE**********************

Option Explicit
Dim xmldoc 'As New MSXML2.DOMDocument40
set xmldoc = CREATEOBJECT("MSXML2.DOMDocument.4.0")
xmldoc.async = False
xmldoc.Load ".\myxml.xml"
Dim xsldoc 'As New MSXML2.DOMDocument40
set xsldoc = CREATEOBJECT("MSXML2.DOMDocument.4.0")
xsldoc.async = False
xsldoc.Load ".\myxsl.xsl"

dim result
result = xmldoc.transformNode(xsldoc)



'Dim XMLDoc
'Dim XSLDoc
'Set XMLDoc = WScript.CreateObject("MSXML.DOMDocument")
'XMLDoc.load WScript.Arguments(0)
'Set XSLDoc = WScript.CreateObject("MSXML.DOMDocument")
'XSLDoc.load WScript.Arguments(1)
Dim OutFile
Dim FSO
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set OutFile = FSO.CreateTextFile(".\results.htm")
'OutFile.Write XMLDoc.transformNode(XSLDoc)
outfile.write result
OutFile.Close


************ ENDVBS FILE**********************
 
Josema said:
Hi to all,

I have a xml file with labels and data.

Im trying to mix both files to generate someting like:

Label A : data of node a
Label B : data of node b
Label C : data of node c

My main problem its that the only thing that i know is that the number of
node labels is equal to the nodes of data.

<MYDataSet>
<Table1>
<A>Label A</A>
<B>Label B</B>
<C>Label C</C>
<D>Label D</D>
</Table1>
<Table3>
<A>Data of Node A</A>
<B>Data of node B</B>
<C>data of node c</C>
<D>data of node d</D>
</Table3>
</MYDataSet>

For other hand i have this xslt sheet:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/MYDataSet">
<table>
<tr>
<td>
<h2>Detalle de electricidad</h2>
</td>
</tr>
<xsl:apply-templates select="Table1"/>
</table>
</xsl:template>
<xsl:template match="Table1/*">
<tr>
<td><xsl:value-of select="."></xsl:value-of></td>
<td><xsl:value-of
select="../../Table3/ancestor::name/."></xsl:value-of></td>
</tr>
</xsl:template>
</xsl:stylesheet>

Please don't multipost. The right place for this question is the XSL group
to which you posted 1 minute or less prior to posting this one. C# is
clearly not the place for an XSL question.
 
Back
Top