使用Shell脚本将XML文件的标签及其值存储在两个不同的数组中

问题描述 投票:0回答:1

我有一个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>&#x0a;</xsl:text>
    </xsl:template>
</xsl:stylesheet>

以类似的方式,我想生成另一个数组,该数组将具有元素作为这些捕获的标签的值。

xml shell xslt
1个回答
0
投票

听起来好像您想使用

© www.soinside.com 2019 - 2024. All rights reserved.