Previous cousin of current element?
Posted: Thu Apr 22, 2010 4:41 pm
Where the current element is derived dynamically. The name is not known...
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ROW>
<HIST_CREATE_DATE>2010-04-15</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user1</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-15</LAST_UPDATE_DATE>
<ALTITUDE>1</ALTITUDE>
</ROW>
<ROW>
<HIST_CREATE_DATE>2010-04-16</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user2</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-16</LAST_UPDATE_DATE>
<ALTITUDE>100</ALTITUDE>
</ROW>
<ROW>
<HIST_CREATE_DATE>2010-04-21</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user1</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-21</LAST_UPDATE_DATE>
<ALTITUDE>50</ALTITUDE>
</ROW>
</ROWSET>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="cyan">
<xsl:for-each select="/ROWSET/ROW[1]/*">
<th>
<xsl:value-of select="name()"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="/ROWSET/*">
<tr>
<xsl:for-each select="./*">
<td>
<xsl:choose>
<!-- Obviously this below is wrong -->
<xsl:when test="text() != name(../preceding-sibling::*[1]/node())">
<!-- Would like to do something like (or something smarter!!!!)
Get the value of the previous sibling with the same name as the current node
<xsl:when test="text() = EVALUATE(name(../preceding-sibling::*[1]/node()))">
OR
<xsl:when test="text() = EVALUATE(concat('../preceding-sibling::*[1]/' ,name()))">
-->
<strong>
<font color="red"> <xsl:value-of select="."/> </font>
</strong>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</td>
TRY: <xsl:value-of select="../preceding-sibling::*[1]/./text()"/>
<xsl:variable name="xxx"
select="concat('../preceding-sibling::*[1]/' ,name())"/>
Constructed Path to previous cousin of current element: <xsl:value-of select="$xxx"/>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>
<table border="1">
<tr bgcolor="cyan">
<th>HIST_CREATE_DATE</th>
<th>ROWID_OBJECT</th>
<th>CREATOR</th>
<th>CREATE_DATE</th>
<th>UPDATED_BY</th>
<th>LAST_UPDATE_DATE</th>
<th>ALTITUDE</th>
</tr>
<tr>
<td>2010-04-15</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-15</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
<tr>
<td>2010-04-16</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user2</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-16</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>100</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
<tr>
<td>2010-04-21</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-21</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>50</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ROW>
<HIST_CREATE_DATE>2010-04-15</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user1</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-15</LAST_UPDATE_DATE>
<ALTITUDE>1</ALTITUDE>
</ROW>
<ROW>
<HIST_CREATE_DATE>2010-04-16</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user2</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-16</LAST_UPDATE_DATE>
<ALTITUDE>100</ALTITUDE>
</ROW>
<ROW>
<HIST_CREATE_DATE>2010-04-21</HIST_CREATE_DATE>
<ROWID_OBJECT>66953 </ROWID_OBJECT>
<CREATOR>user1</CREATOR>
<CREATE_DATE>2007-03-03</CREATE_DATE>
<UPDATED_BY>user1</UPDATED_BY>
<LAST_UPDATE_DATE>2010-04-21</LAST_UPDATE_DATE>
<ALTITUDE>50</ALTITUDE>
</ROW>
</ROWSET>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="cyan">
<xsl:for-each select="/ROWSET/ROW[1]/*">
<th>
<xsl:value-of select="name()"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="/ROWSET/*">
<tr>
<xsl:for-each select="./*">
<td>
<xsl:choose>
<!-- Obviously this below is wrong -->
<xsl:when test="text() != name(../preceding-sibling::*[1]/node())">
<!-- Would like to do something like (or something smarter!!!!)
Get the value of the previous sibling with the same name as the current node
<xsl:when test="text() = EVALUATE(name(../preceding-sibling::*[1]/node()))">
OR
<xsl:when test="text() = EVALUATE(concat('../preceding-sibling::*[1]/' ,name()))">
-->
<strong>
<font color="red"> <xsl:value-of select="."/> </font>
</strong>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()"/>
</xsl:otherwise>
</xsl:choose>
</td>
TRY: <xsl:value-of select="../preceding-sibling::*[1]/./text()"/>
<xsl:variable name="xxx"
select="concat('../preceding-sibling::*[1]/' ,name())"/>
Constructed Path to previous cousin of current element: <xsl:value-of select="$xxx"/>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>
<table border="1">
<tr bgcolor="cyan">
<th>HIST_CREATE_DATE</th>
<th>ROWID_OBJECT</th>
<th>CREATOR</th>
<th>CREATE_DATE</th>
<th>UPDATED_BY</th>
<th>LAST_UPDATE_DATE</th>
<th>ALTITUDE</th>
</tr>
<tr>
<td>2010-04-15</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-15</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
<tr>
<td>2010-04-16</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user2</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-16</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>100</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
<tr>
<td>2010-04-21</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/HIST_CREATE_DATE
<td>66953 </td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ROWID_OBJECT
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATOR
<td>2007-03-03</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/CREATE_DATE
<td>user1</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/UPDATED_BY
<td>2010-04-21</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/LAST_UPDATE_DATE
<td>50</td>
TRY:
Constructed Path to previous cousin of current element: ../preceding-sibling::*[1]/ALTITUDE
</tr>
</table>
</body>
</html>