下午好,
我可以用一只手。最终我想做的是生成一个表,其中填充每行数据,使其以特定列为中心,而数据行居中位置的决定因素是属性“tag=0”。
这是源数据的xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="javascript_mathmax_testbed.xsl"?>
<hall>
<row name="a">
<seat tag="-3">-3_seat_A1</seat>
<seat tag="-2">-2_seat_A2</seat>
<seat tag="-1">-1_seat_A3</seat>
<seat tag="0">+1_seat_A4</seat>
<seat tag="1">+2_seat_A5</seat>
<seat tag="2">+3_seat_A6</seat>
<seat tag="3">+4_seat_A7</seat>
</row>
<row name="b">
<seat tag="-4">-4_seat_B1</seat>
<seat tag="-3">-3_seat_B2</seat>
<seat tag="-2">-2_seat_B3</seat>
<seat tag="-1">-1_seat_B4</seat>
<seat tag="0">+1_seat_B5</seat>
<seat tag="1">+2_seat_B6</seat>
<seat tag="2">+3_seat_B7</seat>
<seat tag="3">+4_seat_B8</seat>
</row>
<row name="c">
<seat tag="-2">-2_seat_C1</seat>
<seat tag="-1">-1_seat_C2</seat>
<seat tag="0">+1_seat_C3</seat>
<seat tag="1">+2_seat_C4</seat>
<seat tag="2">+3_seat_C5</seat>
<seat tag="3">+3_seat_C6</seat>
<seat tag="4">+4_seat_C7</seat>
</row>
<row name="d">
<seat tag="-4">-4_seat_D1</seat>
<seat tag="-3">-3_seat_D2</seat>
<seat tag="-2">-2_seat_D3</seat>
<seat tag="-1">-1_seat_D4</seat>
<seat tag="0">+1_seat_D5</seat>
<seat tag="1">+2_seat_D6</seat>
<seat tag="2">+3_seat_D7</seat>
<seat tag="3">+4_seat_D8</seat>
<seat tag="4">+5_seat_D9</seat>
</row>
<row name="e">
<seat tag="-2">-2_seat_E1</seat>
<seat tag="-1">-1_seat_E2</seat>
<seat tag="0">+1_seat_E3</seat>
<seat tag="1">+2_seat_E4</seat>
<seat tag="2">+3_seat_E5</seat>
</row>
<row name="f">
<seat tag="0">+1_seat_E1</seat>
<seat tag="1">+2_seat_E2</seat>
<seat tag="2">+3_seat_E3</seat>
<seat tag="3">+4_seat_E4</seat>
<seat tag="4">+5_seat_E5</seat>
</row>
<row name="g">
<seat tag="-4">-4_seat_E1</seat>
<seat tag="-3">-3_seat_E2</seat>
<seat tag="-2">-2_seat_E3</seat>
<seat tag="-1">-1_seat_E4</seat>
<seat tag="0">+1_seat_E5</seat>
</row>
</hall>
我的方法可能不是最好的,但我追求的是从属性为“tag=0”的同级中找到每个“行”中先前同级“座位”的数量。然后找到每行的这些兄弟姐妹的最大值是多少,并使用它来相应地移动数据。
这就是我一直在寻找的最终结果:
这是我迄今为止提出的 xsl 样式表:
<?xml version="1.0" encoding="UTF-8"?>
<!--XSLT 1.0 - http://www.CraneSoftwrights.com/training -->
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:inr="http://mycompany.com/mynamespace">
<xsl:variable name="STAtotal" select="count(/hall/row)"/>
<xsl:variable name="Seattotal" select="count(/hall/row/seat)"/>
<!--Attempt_2
<xsl:for-each select="/hall/row/seat[@tag='0']">
<xsl:sort select="count(preceding-sibling::seat[@tag='0'])" order="descending" data-type="number"/>
<xsl:if test="position()=last()">
<xsl:variable name="OSLeft" select="."/>
</xsl:if>
</xsl:for-each>
Attempt_2-->
<head>
<title>Seating_Arrangement_testbed</title>
</head>
<body>
<h2>Seating Arrangement</h2>
<table summary="greatest position of CL" border="1">
<tr align="center">
<th/>
<th>
<b>5th Left Lane</b>
</th>
<th>
<b>4th Left Lane</b>
</th>
<th>
<b>3th Left Lane</b>
</th>
<th>
<b>2th Left Lane</b>
</th>
<th>
<b>1th Left Lane</b>
</th>
<th>
<b>1th Right Lane</b>
</th>
<th>
<b>2th Right Lane</b>
</th>
<th>
<b>3th Right Lane</b>
</th>
<th>
<b>4th Right Lane</b>
</th>
<th>
<b>5th Right Lane</b>
</th>
</tr>
<xsl:for-each select="/hall/row">
<tr align="right">
<td>
<xsl:value-of select="@name"/>
</td>
<xsl:for-each select="./seat">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
<tr>
<xsl:value-of select="$STAtotal"/>
</tr>
<tr>
<xsl:value-of select="$Seattotal"/>
</tr>
<!--Attempt_2
<tr>
<xsl:value-of select="$OSLeft"/>
</tr>
Attempt_2-->
<tr>
<xsl:for-each select="/hall/row/seat[@tag='0']">
<xsl:sort select="count(preceding-sibling::seat[@tag='0'])" order="descending" data-type="number"/>
<xsl:if test="position()=last()">
<xsl:value-of select="count(preceding-sibling::seat)+1"/>
</xsl:if>
</xsl:for-each>
</tr>
</table>
</body>
<!--
<msxsl:script implements-prefix="inr" language="JScript">
function CLPosition(position, STAtotal)
{
// Make sure we have a valid number
if (!isNaN(n))
{
}
return "";
}
</msxsl:script>
-->
</html>
找到这个值的最佳方法是什么?我在想如果我能使用 xslt 和 xpath 获取并存储它就好了,但我不知道这是否可能?也许我需要将 javascript 合并到样式表中才能得到我想要的东西?
使用我的样式表,我相信我已经获得了我正在寻找的值,但我无法将其存储为变量。如果你打开我的样式表,你会看到注释掉的代码“