我有一个XML格式的文件:
<classes>
<subject>
<name>Operating System</name>
<credit>3</credit>
<type>Theory</type>
<faculty>Prof. XYZ</faculty>
</subject>
<subject>
<name>Web Development</name>
<credit>3</credit>
<type>Lab</type>
</subject>
</classes>
预期输出:
index 0 : name- Operating System
index 1 : credit- 3
index 2 : type- Theory
index 3 : faculty- Prof. XYZ
index 4 : name- Web Development
index 5 : credit- 3
index 6 : type- Lab
借助.xsl
文件,我能够生成所有标签名称的数组。
命令是:tagArr=($( xsltproc tag_name.xsl file.xml ))
tag_name.xsl
文件是:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="*" />
<xsl:template match="/classes/subject/*">
<xsl:value-of select="name(.)" /><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
以类似的方式,我想生成另一个数组,该数组将具有元素作为这些捕获的标签的值。
听起来好像您想使用