说我有这个给定的xml文件
<root>
<node>x</node>
<node>y</node>
<node>a</node>
</root>
Run Code Online (Sandbox Code Playgroud)
我想要显示以下内容
ayx
Run Code Online (Sandbox Code Playgroud)
使用类似的东西
<xsl:template match="/">
<xsl:apply-templates select="root/node"/>
</xsl:template>
<xsl:template match="node">
<xsl:value-of select="."/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud) 我发现这个页面描述了Muenchian方法,但我认为我错误地应用了它.
考虑到这将返回一组年龄:
/doc/class/person/descriptive[(@name='age')]/value
Run Code Online (Sandbox Code Playgroud)
1..2..2..2..3..3..4..7
但我希望每个年龄段的节点集只有一个节点.
1..2..3..4..7
这些中的每一个似乎都返回所有值,而不是唯一值:
/doc/class/person/descriptive[(@name='age')][not(value=preceding-sibling::value)]/value
/doc/class/person/descriptive[(@name='age')]/value[not(value=preceding-sibling::value)]
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
如何使用xsl 1.0获取文件名?
我试过了
<xsl:value-of select="base-uri()" />
Run Code Online (Sandbox Code Playgroud)
但得到了"致命的错误!无法找到功能:base-uri"
我有一个带有时间戳的XML,如下所示:
<node stamp="1236888746689" />
Run Code Online (Sandbox Code Playgroud)
我想在结果HTML中将它们显示为日期和时间.有没有办法用XSLT(任何版本)做到这一点?
编辑: 我正在使用XSLT2.0与Saxon9.基准日期是1970-01-01 0:00.
我的一位大四学生证明了这一点,我想知道这是一个缺陷,还是有一些优先级和操作员关联性的东西证明了这一点.
>>> False==False in [False]
True
Run Code Online (Sandbox Code Playgroud) 如何计算XSLT中节点中的不同值?
示例:我想计算Country节点中现有国家/地区的数量,在这种情况下,它将为3.
<Artists_by_Countries>
<Artist_by_Country>
<Location_ID>62</Location_ID>
<Artist_ID>212</Artist_ID>
<Country>Argentina</Country>
</Artist_by_Country>
<Artist_by_Country>
<Location_ID>4</Location_ID>
<Artist_ID>108</Artist_ID>
<Country>Australia</Country>
</Artist_by_Country>
<Artist_by_Country>
<Location_ID>4</Location_ID>
<Artist_ID>111</Artist_ID>
<Country>Australia</Country>
</Artist_by_Country>
<Artist_by_Country>
<Location_ID>12</Location_ID>
<Artist_ID>78</Artist_ID>
<Country>Germany</Country>
</Artist_by_Country>
</Artists_by_Countries>
Run Code Online (Sandbox Code Playgroud) 我有一个XSL样式表,其中包含如下xsl:text
节点中的内容:
<xsl:text>
foo
bar
baz
</xsl:text>
Run Code Online (Sandbox Code Playgroud)
样式表本身是一个带有"unix-style"换行符终结符的文本文件.我在Windows上调用此样式表以及类似unix的平台.将输出符合调用它的平台的约定会很好.
当我在Windows上运行此样式表时,输出具有除xsl:text
节点内容之外的所有内容的回车符/换行符对.
我是否可以指示XSLT处理器将xsl:text
节点内容中的换行符转换为特定于平台的行尾?
更多上下文:我正在调用Apache Ant 1.7.1 XSLT任务中的样式表,如下所示:
<xslt in="in.xml" out="out.xml" style="stylesheet.xsl"/>
Run Code Online (Sandbox Code Playgroud)
样式表标题目前如下所示:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
exclude-result-prefixes="xalan">
<!-- contents elided -->
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud) 我有一个类似:::的XML文档
<?xml version="1.0" encoding="utf-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Worksheet ss:Name="Worksheet1">
<Table>
<Column ss:Width="100"></Column>
<Row>
<Cell ss:Index="1" ss:StyleID="headerStyle">
<Data ss:Type="String">Submitted By</Data>
</Cell>
</Row>
<Row>
<Cell ss:Index="1" ss:StyleID="alternatingItemStyle">
<Data ss:Type="String">Value1-0</Data>
</Cell>
</Row>
</Table>
<AutoFilter xmlns="urn:schemas-microsoft-com:office:excel"
x:Range="R1C1:R1C5"></AutoFilter>
</Worksheet>
</Workbook>
Run Code Online (Sandbox Code Playgroud)
问题是尝试选择Rows时
<xsl:for-each select="//Row">
<xsl:copy-of select="."/>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)
它不匹配.我删除了所有的名称间距,它工作正常.那么,如何让'select'匹配Row?
请找到以下xsl-fo,尝试为pdf中的每个页面设置页眉和页脚,但在最后一页只有第一页和页脚的页眉.但在这里我需要每一页.如何执行此操作.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match='/'>
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page"
page-height="29.7cm"
page-width="21cm"
margin-top="1cm"
margin-bottom="0.1cm"
margin-left="0.8cm"
margin-right="1.0cm" >
<fo:region-body margin-top="2.5cm" margin-bottom="2.5cm"/>
<fo:region-before extent="2.0cm"/>
<fo:region-after extent="2.0cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-before">
<fo:block>
Message Body
</fo:block>
</fo:flow>
<fo:flow flow-name="xsl-region-body">
Message Content
</fo:flow>
<fo:flow flow-name="xsl-region-after">
<h2>
Page Footer
</h2>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="replace-returns">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<xsl:value-of select="'<br />'" disable-output-escaping="yes"/>
<xsl:call-template name="replace-returns">
<xsl:with-param name="text" select="substring-after($text, '
')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of …
Run Code Online (Sandbox Code Playgroud) 我试图找到一种简单的方法来修改Windows下使用python的文件时间戳,但网上没有太多清晰的信息.经过一段时间的搜索,我得到了解决方案 为了缩短对其他人的搜索,代码如下.
它可能更容易,更美丽,但它的工作原理.我唯一没有解决的问题是夏季时间 - 冬季时间问题,即如果给出夏季时间,则结果相差一小时.也许有人可以添加更正?
from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle
from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING
from pywintypes import Time
import time
import sys
import os
if len(sys.argv)<5:
pfile = os.path.basename(sys.argv[0])
print "USAGE:\n\t%s <createTime> <modifyTime> <accessTime> <FileName>\n" % pfile
print "EXAMPLE:"
print '%s "01.01.2000 00:00:00" "01.01.2000 00:00:00" "01.01.2000 00:00:00" file' % (pfile)
sys.exit()
# get arguments
cTime = sys.argv[1] # create
mTime = sys.argv[2] # modify
aTime = sys.argv[3] # access
fName = sys.argv[4]
# specify time format …
Run Code Online (Sandbox Code Playgroud)