Visual Studioを使用して開発中に変換を実行すると、結果のxmlには、テンプレートの基準に一致しないタグに含まれていた宛先のソースxmlからのテキストが含まれます
最初のテンプレートで選択したGroupが、 CrystalReportの直接の子であるGroupという名前の要素を見つけて、それらをapplytemplate呼び出しで渡すことを期待していました。2番目のテンプレートの一致フィルターは、 Level = 1の属性を持つグループのみを取り込み、それらを書き出すことを理解しました。他のすべては無視されると思います。
「これではない」が出力に表示されるのはなぜですか?
ソース
<?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>