- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 XML:
(纸上的 child 可以是我现阶段不知道的任何节点名称)
<catalog>
<Paper result="false">Paper1</Paper>
<Books result="true">Books1</Books>
<Books result="true">Books2</Books>
<Books result="true">Books3</Books>
<Books result="true">Books4</Books>
<Paper result="false">Paper2</Paper>
<Books result="false">Books5</Books>
<Paper result="false">Paper3</Paper>
<Books result="true">Books6</Books>
<Books result="true">Books7</Books>
<Books result="false">Books8</Books>
<Paper result="false">Paper4</Paper>
<Paper result="false">Paper5</Paper>
<Books result="true">Books9</Books>
<Books result="true">Books10</Books>
<Books result="true">Books11</Books>
<Books result="true">Books12</Books>
<Books result="true">Books13</Books>
<Books result="true">Books14</Books>
<Books result="false">Books15</Books>
</catalog>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>RESULT</th>
</tr>
<xsl:for-each select="catalog/child::*">
<tr>
<td>
<xsl:value-of select="."/> |
<xsl:value-of select="@result"/> =
<xsl:value-of select="( self::Books and following-sibling::*[1][self::Books] ) or
( self::Books and preceding-sibling::*[1][self::Books] and not( following-sibling::*[1][self::Books] ) and not( preceding-sibling::*[position()=2][self::Books] ) ) or
( self::Books and preceding-sibling::*[1][self::Books] and preceding-sibling::*[position()=1][self::Books] and preceding-sibling::*[position()=2][self::Books] and preceding-sibling::*[position()=3][self::Books] ) " />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Paper1 | false = false
Books1 | true = true
Books2 | true = true
Books3 | true = true
Books4 | true = true
Paper2 | false = false
Books5 | false = false
Paper3 | false = false
Books6 | true = true
Books7 | true = true
Books8 | false = false
Paper4 | false = false
Paper5 | false = false
Books9 | true = true
Books10 | true = true
Books11 | true = true
Books12 | true = true
Books13 | true = true
Books14 | true = true
Books15 | false = true
<table>
<tr><td>Paper1</td></tr>
</table>
<table>
<tr><td>Books1</td></tr>
<tr><td>Books2</td></tr>
</table>
<table>
<tr><td>Books3</td></tr>
<tr><td>Books4</td></tr>
</table>
<table>
<tr><td>Paper2</td></tr>
</table>
<table>
<tr><td>Books5</td></tr>
</table>
<table>
<tr><td>Paper3</td></tr>
</table>
<table>
<tr><td>Books6</td></tr>
<tr><td>Books7</td></tr>
</table>
<table>
<tr><td>Books8</td></tr>
</table>
<table>
<tr><td>Paper4</td></tr>
</table>
<table>
<tr><td>Books9</td></tr>
<tr><td>Books10</td></tr>
</table>
<table>
<tr><td>Books11</td></tr>
<tr><td>Books12</td></tr>
</table>
<table>
<tr><td>Books13</td></tr>
<tr><td>Books14</td></tr>
</table>
<table>
<tr><td>Books15</td></tr>
</table>
最佳答案
这并不像我一开始错误地认为的那么微不足道。尝试:
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="grpOfBooks" match="Books" use="count(preceding-sibling::*[not(self::Books)])" />
<xsl:template match="/catalog">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="catalog/*[not(self::Books)]">
<table>
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="Books [count(. | key('grpOfBooks', count(preceding-sibling::*[not(self::Books)]))[1]) = 1]">
<xsl:for-each select="key('grpOfBooks',count(preceding-sibling::*[not(self::Books)]))[position() mod 2 = 1] ">
<table>
<tr>
<td><xsl:value-of select="."/></td>
<xsl:if test="following-sibling::*[1][self::Books]">
<td><xsl:value-of select="following-sibling::Books[1]"/></td>
</xsl:if>
</tr>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="Books"/>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/catalog">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="catalog/*[not(self::Books)]">
<table>
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="Books[not(preceding-sibling::*[1][self::Books])]">
<xsl:variable name="grp" select="count(preceding-sibling::*[not(self::Books)])" />
<xsl:for-each select="(. | following-sibling::Books) [count(preceding-sibling::*[not(self::Books)])=$grp] [position() mod 2 = 1] ">
<table>
<tr>
<td><xsl:value-of select="."/></td>
<xsl:if test="following-sibling::*[1][self::Books]">
<td><xsl:value-of select="following-sibling::Books[1]"/></td>
</xsl:if>
</tr>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="Books"/>
</xsl:stylesheet>
关于Xslt, Xpath 以一对二对子节点进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24110624/
我想添加子类别并在列表上使用react,但是当我单击子类别时,我有两个事件:第一个在子类别上,第二个在父类别上。 我怎样才能只有子类别? 这是我的实际代码: getList(myList){
我有一个问题。我有 1:N 关系(用户:任务)。我需要查询所有用户的列表,其中每个用户都有其任务列表 - 按日期(指定属性)排序。 最佳答案 获取用户 RealmResults users = rea
考虑以下代码片段: OPTIONS Email 每当我将鼠标悬停在 上时,
我正在与 PF4J(Plugin Framework for Java) 的开发者合作为 Wicket 提供更好的插件功能。已经有一个 pf4j-spring 和一个 pf4j-wicket 项目来提
我有一个带有 SVG 子元素的父元素(SVG 是一个简单的立方体)。父级的 CSS 不透明度 = 0.45。在 Android/Webview 上显示不透明度值在渲染时应用于各个 SVG 多边形,导致
我试图放置一个标签,使标签的顶部位于 UIViewController 下方的 2/3 处。所以我写了这个约束,但它给了我下面的错误。 NSLayoutConstraint *labelTopCons
我是一名优秀的程序员,十分优秀!