使用Visual Studio在開發過程中執行轉換時,生成的xml包含目標中的源xml文本,該文本包含在與我的模板條件不匹配的標記中XSLT(XML to XML)輸出包含源不匹配的數據
我期待我的選擇集團在第一個模板找到名爲組,是CrystalReport直接孩子的任何元素,並通過他們在應用模板調用。我知道我的第二個模板上的匹配過濾器只會在組的屬性爲Level = 1並將其寫出。我期望一切被忽略。
爲什麼「not this」出現在我的輸出中?
源
<?xml version="1.0" encoding="utf-8" ?>
<!--
UPDATE: Note that adding the xmlns attribute causes all output
to disappear unless you use Chris's second solution.
-->
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" >
<Group Level="1">
<GroupHeader>
<Section>
<Field FieldName="apple" />
</Section>
</GroupHeader>
<Group Level="2">
not this
</Group>
</Group>
</CrystalReport>
變換
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/CrystalReport">
<root>
<xsl:apply-templates select="Group"/>
</root>
</xsl:template>
<xsl:template match="Group[@Level='1']/GroupHeader">
<tag1><xsl:value-of select="Section/Field/@FieldName"/></tag1>
</xsl:template>
</xsl:stylesheet>
輸出
<?xml version="1.0" encoding="utf-8"?>
<root>
<tag1>apple</tag1>
not this
</root>
謝謝,並獲得成功,我曾讀過關於空模板)匹配的文本(但必須用我的基本模板 – 2012-04-11 10:46:22
無根的比賽一直很高興幫助,您的評論促使我使用更多原始代碼添加一個稍微更乾淨的示例。 – 2012-04-11 10:53:53
我的示例是真正問題的簡化示例,現在我發現將名稱空間添加回CrystalReport元素會導致不返回數據(xmlns =「urn:crystal-reports:schemas:report-detail」) ,我相信我已經看到了名稱空間解決方案,我會看看。感謝您的更新,我也會嘗試。 – 2012-04-11 11:23:08