我经常得到一些未按预期格式化的 XML,并且正在寻找自动修复它的最佳方法。不幸的是,解决方案是在我头上滑冰。
我正在研究杂志内容,并且很难处理两个特定元素。
There are <subhead> elements, and <body> elements. Even though the subhead element should always be on it's own, sometimes the proofer will accidentally nest it with a <body> node.
<subhead> nodes should be formatted as their own paragraph, wrapped in <p> and <strong> tags.
<body> nodes should just be wrapped in <p> tags.
So I could get either:
<subhead>Dogs</subhead>
<body>Dogs do not like cats.</body>
or
<body><subhead>Dogs</subhead> Dogs do not like cats.</body>
I would like either scenario to output as:
<p><strong>Dogs</strong></p>
<p>Dogs do not like cats.</p>
目前,我的代码看起来像..
<xsl:for-each select="//default:textObject/default:text/*">
<xsl:for-each select="./*">
<xsl:choose>
<xsl:when test="@name='subhead'">
<p><strong>
<xsl:apply-templates select="node()"/>
</strong></p>
</xsl:when>
<xsl:when test="@name='body'">
<p>
<xsl:apply-templates select="node()"/>
</p>
</xsl:when>
...
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
我怎样才能相应地调整它来解决这个问题?
谢谢你。