我下面的样式表似乎与文档中的所有文本数据匹配,我希望仅针对一个富文本元素并遍历每个 par 元素下的每个 run 元素。
XML:
<?xml version='1.0' encoding='utf-8'?>
<document xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.lotus.com/dxl xmlschemas/domino_8_5_3.xsd'
xmlns='http://www.lotus.com/dxl' version='8.5' maintenanceversion='3.0' replicaid='934850394858534'
form='formreq'>
<noteinfo noteid='234234' unid='02934802938402934023942934' sequence='11'>
<created><datetime dst='true'>20130510T150111,26-05</datetime></created>
<modified><datetime dst='true'>20130513T095937,29-05</datetime></modified>
<revised><datetime dst='true'>20130513T095946,19-05</datetime></revised>
<lastaccessed><datetime dst='true'>20130513T093454,28-05</datetime></lastaccessed>
<addedtofile><datetime dst='true'>20130510T150342,15-05</datetime></addedtofile></noteinfo>
<item name="criteria">
<richtext>
<pardef id='1' leftmargin='0.0500in' rightmargin='97%' keepwithnext='true' keeptogether='true'/>
<par def='1'><run><font style='bold' name='Arial' pitch='variable' truetype='true' familyid='20'/>This is a test.</run></par>
<par def='1'><run><font style='bold' name='Arial' pitch='variable' truetype='true' familyid='20'/>And this is another test.</run></par>
</richtext>
</item>
</document>
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dxl="http://www.lotus.com/dxl" >
<xsl:template match="dxl:document/dxl:item[@name='criteria']/dxl:richtext">
<div id="criteria">
<xsl:for-each select="par">
<xsl:for-each select="run">
<xsl:text>It worked!</xsl:text>
</xsl:for-each>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
我觉得这是一个命名空间问题。我也在几个不同的转换引擎上尝试过这个并收到相同的结果:
<?xml version="1.0"?>
20130510T150111,26-05
20130513T095937,29-05
20130513T095946,19-05
20130513T093454,28-05
20130510T150342,15-05
<div xmlns:dxl="http://www.lotus.com/dxl" id="criteria"/>
我不确定为什么日期时间戳甚至匹配,因为这不是我匹配标准的一部分。
http://www.online-toolz.com/tools/xslt-transformation.php提供了帮助实时测试的工具