以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XSL/XSLT/XSL-FO/CSS 』 (http://bbs.xml.org.cn/list.asp?boardid=8) ---- 节点集中以某个节点为界分开处理怎么实现? (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=19039) |
-- 作者:kahon -- 发布时间:5/30/2005 8:53:00 PM -- 节点集中以某个节点为界分开处理怎么实现? 对于一个xml文档,在其中某个节点以前用一种(假设为第一种)处理方式,某节点后也用同样的方式。只有遇到某类节点时用第二中处理方法。 象xml文档中,<p></p>之间可能嵌套<table>等,我要在xsl文件中写一些处理,对于不是<table>的标签用第一种方法,对于任何的<table><img>等标签用第二种处理方法。但是顺序要跟在刚才第一的处理后。然后对其后的节点再用第一种方法。我想用xsl实现,因为转换比较复杂,不想用编程语言写,不知道直接写xsl文件可行不,高手请指教。 例如: <p> <Text> |
-- 作者:kahon -- 发布时间:5/30/2005 10:14:00 PM -- 写了如下的框架。就是不知道怎么选择分界节点之前的所有节点,怎么表示。 <xsl:template match="body/p"> <!-- ============================================ 分情况,如果子孙中根本没有此类分界的节点,不用那么麻烦,否则只好处理 =============================================== --> <xsl:choose> <xsl:when test="not(descendant::img | descendant::table)"> <Text> processing for the Text </Text> </xsl:when> <xsl:otherwise> </xsl:choose> |
-- 作者:kahon -- 发布时间:5/31/2005 11:22:00 PM -- 摘自exslt的set:leading 可以实现第一个参数nodeset中截取第二个参数nodeset的第一个节点第一次出现前的所有部分。 <xsl:template name="set:leading"> <xsl:param name="nodes" select="/.." /> <xsl:param name="node" select="/.." /> <xsl:variable name="end-node" select="$node[1]" /> <xsl:choose> <xsl:when test="not($end-node) or not($nodes)"> <xsl:apply-templates select="$nodes" mode="set:leading" /> </xsl:when> <xsl:when test="count($end-node|$nodes) != count($nodes) or count($nodes[1] | $end-node) = 1" /> <xsl:otherwise> <xsl:apply-templates select="$nodes[1]" mode="set:leading" /> <xsl:call-template name="set:leading"> <xsl:with-param name="nodes" select="$nodes[position() > 1]" /> <xsl:with-param name="node" select="$end-node" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="node()|@*" mode="set:leading"> |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
62.500ms |