使用shell xmlstarlet从xml文件中删除最后一个逗号
我得到了使用shell xmlstarlet从xml文件中删除最后一个逗号,xml,bash,shell,xmlstarlet,Xml,Bash,Shell,Xmlstarlet,我得到了comp.xml文件,其中包含 <project name="installer" > <property name="workflow.list" > BTCH.WF_BatchRequest_Process.BatchRating, BTCH.WF_BatchRequest_Process.Invoice, </property> <property name="wfGroup.list" > BTCH.WFG_BatchResPr
comp.xml
文件,其中包含
<project name="installer" >
<property name="workflow.list" >
BTCH.WF_BatchRequest_Process.BatchRating,
BTCH.WF_BatchRequest_Process.Invoice,
</property>
<property name="wfGroup.list" >
BTCH.WFG_BatchResPrep,
BTCH.WFG_BatchRes,
</property>
<target name="shutdown">
<echo>shutdown</echo>
</target>
</project>
BTCH.WF\U批处理请求\U过程.BatchRating,
BTCH.WF\u批处理请求\u过程发票,
BTCH.WFG_BatchResPrep,
BTCH.WFG_BatchRes,
关闭
如果存在逗号,我需要使用shell删除每个
标记中的最后一个“,”逗号
因此,它应该是:
<project name="installer" >
<property name="workflow.list" >
BTCH.WF_BatchRequest_Process.BatchRating,
BTCH.WF_BatchRequest_Process.Invoice
</property>
<property name="wfGroup.list" >
BTCH.WFG_BatchResPrep,
BTCH.WFG_BatchRes
</property>
<target name="shutdown">
<echo>shutdown</echo>
</target>
</project>
BTCH.WF\U批处理请求\U过程.BatchRating,
BTCH.WF\u批处理请求\u过程发票
BTCH.WFG_BatchResPrep,
BTCH.WFG\u BatchRes
关闭
如果您知道属性值总是以
结尾,那么下面的xslt对我来说是有效的(至少对您的示例数据有效)
以上大部分内容都是简单的。剩下的只是
属性
元素的匹配和少量的文本操作。awk-v RS=“”{sub(“,$”,“,”,$NF)}{print$0,RS}文件
创建了它,但破坏了格式。我的文件更大。。。如果没有格式化,它看起来很糟糕:(我找到了一个解决方案。硬代码,但在我的情况下它是有效的…sed]:a;N;$!ba;s/,\N你能推荐一本书吗?这将摆脱使用xslt的这种启发程度吗?我意识到这对s.O来说是不合适的。所以“否”也是一个可以接受的答案:-)祝大家好运。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="property">
<xsl:copy>
<xsl:value-of select="substring(text(), 1, string-length(text()) - 2)"/><xsl:text>
</xsl:text>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>