2010-12-13
XPATH点滴
/ 符号:以前基本上认为就是在轴上分隔不同的节点。更广义的理解是这是一个高阶的运算符。比如$EXP1和$EXP2 分别为两个节点集合,那么$EXP1/$EXP2表示对$EXP1中的每一个节点对$EXP2求值,$EXP1/$EXP2的值即为:对$EXP1中每个节点对$EXP2求值的集合。
对轴的理解:轴实际上是一种节点间一对多的映射,可以把轴理解为一种函数,输入为一个单个节点,输出为与该节点有某种关系的节点的集合。
(@code,"N/A")[1]:如果code属性的值不为空,那么这个表达式的值即为code属性的值,否则返回”N/A”。因为当code属性的值为空时,通过运算符逗号 “,” 创建的sequence只有一个item即”N/A”,筛选条件[1]选择sequence中第一个元素。
2009-06-10
删除一对XML标签内的文字2
我的尝试:
:%s/\(<script \a*="\a*\/x-javascript">\)\([^<]*\)\(<\/script>\)/\1\3/
或者
:%s#\(<script contentType="application/x-javascript">\)[^<]*\(</script>\)#\1\2#
用sed来处理:
sed -rn 's#(<script contentType="application/x-javascript">)[^<]*(</script>)#\1\2#g;p' myfile.xdp
如果脚本有多行,需要处理换行的情况:
%s#\(<script contentType="application/x-javascript">\)\([^<]*\n\)*[^<]*\(</script>\)#\1\3#g
或者用awk来处理换行的情况:
awk -v RS="<script contentType=\"application/x-javascript\">" 'NR!=1{gsub("^[^<]*</script>","</script>")}{printf NR==1?$0:RS""$0}' myfile.xdp
Update: (2009-06-24 )
要干净删除已有的脚本代码,仅仅删除<script>标签内的代码还不够。这样会留下很多空的不包含脚本的event标签,当再次添加脚本文件时,如果新生成的event标签连同script标签在原来那个标签之后,那么代码将不会在design view下显示出来,而只在XML source中显示出来,在执行时,代码仍会被执行。也就是说,一个不包含任何代码代码的form的xml source里面应该有不会有event标签出现。
2009-05-31
删除一对xml标签内的文字
<script contentType="application/x-javascript">$.rawValue = ValidateScriptObject.fmtDate(ValidateScriptObject.getPeriod(),1);</script>
LiveCycle Designer不提供一次性删除所有的javascript代码,只好自己动手。在vim下先查找x-javascript,然后执行 cit 来删除标签内的文字,然后击键 n . ,这样下去似乎很快捷,不过后来发现当标签内文字不为空时,命令执行的很好,当这是一对空标签时,cit 命令会删除开始标签,导致XML文件不再well formed,后来在bbs.chinaunix.com一问才知道,这是gvim 7.1的一个bug,7.2修正了这个问题。
2007-08-14
O2使用cocoon服务器
在浏览O2的网页时,发现其Pagerank值为零,另外URL里出现cocoon-action-DisplayCDRs等字样,便猜测会不会跟cocoon有关。查看服务器返回的Header,果然使用的是cocoon,版本号为2.1.9,而2.1.10正式版在2006年12月就发布了。看来对于企业生产环境来说,更换网页服务器不是一件简单的事。
2007-07-28
cocoon环境下在XSLT中使用request parameter
<use-request-parameters>false</use-request-parameters>
的值改为:
<use-request-parameters>true</use-request-parameters>
这样在XSLT中声明一下这个parameter就可以使用了:
<xsl:param name="parameter-name"/>
2007-07-06
在XSLT中为元素添加属性
想把一个XML文件中一个原来是一个元素的子元素变为该元素的属性,如:
<item>
<itemText>f. 3v: cath 3, 80-134 </itemText>
<link>003_v.jpg</link>
</item>
<item>
<itemText>f. 4r: cath 3, 135-199 </itemText>
<link>004_r.jpg</link>
</item>
<item>
<itemText>f. 4v: cath 3, 200-4, 52 </itemText>
<link>004_v.jpg</link>
</item>
使用下面的XSLT语句可以为item元素增加name属性,但是没有删除子元素<link>,只好用vi来删除了:)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="//item">
<xsl:copy>
<xsl:attribute name="name"><xsl:value-of select="./link" /></xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
2007-04-10
Dremaweaver 8的bug?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML LANG="de">
<HEAD>
<TITLE>"Suche"</TITLE>
<LINK href="./skin/KaPr_basis_structure.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_top.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_header_footer.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_left_menue.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_left_suchformular.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_left_funktionsunterscheidung.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_text_treffer.css" REL="stylesheet" TYPE="text/css"/>
<LINK href="./skin/KaPr_Color_Fonts.css" REL="stylesheet" TYPE="text/css"/>
</HEAD>
... ...
</HTML>
用其他的编辑器,如vim,打开就不是这样,所有的元素名保持原来的大小写。这里Dreamweaver应该算是画蛇添足,算作Dreamweaver的一个bug?
2007-04-04
在XSL中对变量作加法
在XSL中对变量作加法:
如果使用的转换器只支持XSLT 1.0,则:
<xsl:variable name="n1">
<xsl:choose>
<xsl:when test="number($t1) = number($t1)">
<xsl:value-of select="$t1"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="n2">
<xsl:choose>
<xsl:when test="number($t2) = number($t2)">
<xsl:value-of select="$t2"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="temp1" select="$n1 + $n2"/>
如果XSLT parser支持XSLT 2.0:
XSLT 2.0 makes it easier because of the conditional expressions in XPath 2.0. You can do:
<xsl:variable name="n1"
select="if (number($t1) = number($t1)) then $t1 else 0" />
<xsl:variable name="n2"
select="if (number($t2) = number($t2)) then $t2 else 0" />
<xsl:variable name="temp1" select="$n1 + $n2" />
Depending on how you're getting the values of $t1 and $t2 (and the final definition of if-absent()) it might also be possible to use the if-absent() function:
<xsl:variable name="temp1" select="if-absent($t1, 0) + if-absent($t2, 0)" />
2007-03-23
Exchanger XML Editor
2006-07-12
学习Xinclude
以前经常看IBM developerworks的文章,今天在网上想学习一下Xinclude,才发现MSDN也有不少好文章,如这篇将 XML 文档与 XInclude 合并在一起。
这儿是实现Xinclude的一个列表(截至2003年6月),Cocoon榜上有名。
2006-07-09
FOP and Embedding Fonts under Cocoon
2006-07-07
xsl和xslt文件扩展名的问题
如果选择创建xsl文件,则程序生成的文件头为:
2006-06-19
学习XSP 1
XSP文件的根元素为<page>,通常使用xsp名字空间(<xsp:page>)。
一个简单的例子如:
2005-07-25
学习XSLT
XSLT文件本身符合XML规范,包括多个templates。templates在源文档为基础查找匹配的机构已根据规则生成新的文档,在源文档中定位则采用W3C的XPath标准。