After XSLT execution i have a picture like (some attributes with empty values)
(XSLT执行后,我有一张类似的图片(某些属性值为空))
<Document
Region="Earth"
City="Tokio"
District=""
Street="" >
</Document>
My XSLT was
(我的XSLT是)
<xsl:template match="Document">
<Document
Region="{Region/@attr1}"
City="{City/@attr2}"
District="{District/@attr3}"
Street="{Street/@attr4}" >
<xsl:apply-templates />
</Document>
</xsl:template>
All Xpathes are correct.
(所有Xpathes都是正确的。)
The thing is that, as i suppose, my code is too "direct". (事实是,正如我想的那样,我的代码太“直接”了。)
Need more flexibilty. (需要更多的灵活性。)
Briefly, compliance of the condition: "If there is no value\attribute to catch in source XML then there shouldn't be any corresponding record in the output node". (简要地说,符合条件:“如果没有值\属性可捕获源XML,则输出节点中不应有任何相应的记录”。)
In the sample code {District/@attr3} and {Street/@attr4} Xpath\Expression may return some values but sometimes are not (there is even no attribute in the source node then). (在示例代码{District / @ attr3}和{Street / @ attr4}中,Xpath \ Expression可能返回一些值,但有时不返回(这样,源节点中甚至没有属性)。)
So desired output in case when {District/@attr3} and {Street/@attr4} return\"matching" nothing have to looks like: (因此,在{District / @ attr3}和{Street / @ attr4}返回\“ matching”的情况下,期望的输出没有什么变化:)
Desired output
(所需的输出)
<Document
Region="Earth"
City="Tokio" >
</Document>
How to improve XSLT code (1.0)?
(如何改进XSLT代码(1.0)?)
ask by Alex translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…