Michael K?nig
Usenet Archive
- Joined
- Apr 21, 2005
- Messages
- 1
- Reaction score
- 0
Hello,
I've an XML-file structured like this
<table>
<tr>
<td>Nombre:</td>
<td>Joseph</td>
<td>Apellido:</td>
<td>Ratzinger</td>
<td>Posición:</td>
<td>Pope</td>
</tr>
</table>
I'like to extract the personal data depending on the label which stands in the sibling <td> before, the result should look like this:
<person>
<name>Joseph</name>
<surname>Ratzinger</surname>
<profession>Pope</profession>
</person>
I know what labels can appear ("Nombre:", "Apellido:","Posición:") but I don't know if they appear within the <tr>-Element and in which order, so I can't use [position=2] etc.
How do I realize this using XSLT?
I tried
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl
utput method="text" encoding="ISO-8859-1"/> <xsl:template match="table"> <person> <name><xsl:apply-templates select="td[text='Nombre:']"/></name> <surname><xsl:apply-templates select="td[text='Appellido:']"/></surname> <profession><xsl:apply-templates select="td[text='Posición:']"/></profession> </person> </xsl:template>
<xsl:template match="td[text='Nombre:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
<xsl:template match="td[text='Appellido:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
<xsl:template match="td[text='Posición:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
</xsl:stylesheet>
But the problem I have is that 'following-sibling::td' accesses ALL following-siblings and not only the next. I could imagine a solution making use of something like
[position=td[text='Nombre:']position+1]
but I don't know how to implemt it in XSLT.
Any suggestion? Thanks in advance.
Michael
I've an XML-file structured like this
<table>
<tr>
<td>Nombre:</td>
<td>Joseph</td>
<td>Apellido:</td>
<td>Ratzinger</td>
<td>Posición:</td>
<td>Pope</td>
</tr>
</table>
I'like to extract the personal data depending on the label which stands in the sibling <td> before, the result should look like this:
<person>
<name>Joseph</name>
<surname>Ratzinger</surname>
<profession>Pope</profession>
</person>
I know what labels can appear ("Nombre:", "Apellido:","Posición:") but I don't know if they appear within the <tr>-Element and in which order, so I can't use [position=2] etc.
How do I realize this using XSLT?
I tried
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl
<xsl:template match="td[text='Nombre:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
<xsl:template match="td[text='Appellido:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
<xsl:template match="td[text='Posición:']">
<xsl:value-of select="following-sibling::td" />
</xsl:template>
</xsl:stylesheet>
But the problem I have is that 'following-sibling::td' accesses ALL following-siblings and not only the next. I could imagine a solution making use of something like
[position=td[text='Nombre:']position+1]
but I don't know how to implemt it in XSLT.
Any suggestion? Thanks in advance.
Michael