我有一个 XML 文件(test.xml),内容如下:
<hudson>
<job>
<name>cedge</name>
</job>
<job>
<name>techM</name>
</job>
<job>
<name>infy</name>
</job>
<job>
<name>DevP</name>
<job>
<name>line</name>
<nextBuildNumber>14</nextBuildNumber>
</job>
<job>
<name>ment</name>
<nextBuildNumber>85</nextBuildNumber>
</job>
<job>
<name>FreeS</name>
<nextBuildNumber>96</nextBuildNumber>
</job>
<job>
<name>test</name>
</job>
</job>
<job>
<name>Email</name>
</job>
<job>
<name>investigate</name>
<nextBuildNumber>26</nextBuildNumber>
</job>
<job>
<name>Java</name>
</job>
<job>
<name>Tools</name>
</job>
</hudson>
需要输出以下格式的文件:
"line" "14"
"ment" "85"
"FreeS" "96"
"investigate" "26"
尝试以下方法:
xsltproc x.xslt test.xml
按以下方式制作x.xslt:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//job">
"<xsl:value-of select="name"/>" = "<xsl:value-of select="nextBuildNumber"/>"
</xsl:template>
</xsl:stylesheet>
仅获取
"investigate" = "26"
一起处理空值。无法从“job-Devp”标签获取数据,希望能得到帮助。