0
我正在使用XSLT首次嘗試將一些XML數據提取爲CSV格式。這是一個有點輸入:在XSLT中包含Nest作爲獨立實體
<diag>
<name>A08</name>
<desc>Viral and other specified intestinal infections</desc>
<excludes1>
<note>influenza with involvement of gastrointestinal tract (J09.X3, J10.2, J11.2)</note>
</excludes1>
<diag>
<name>A08.0</name>
<desc>Rotaviral enteritis</desc>
</diag>
<diag>
<name>A08.1</name>
<desc>Acute gastroenteropathy due to Norwalk agent and other small round viruses</desc>
<diag>
<name>A08.11</name>
<desc>Acute gastroenteropathy due to Norwalk agent</desc>
<inclusionTerm>
<note>Acute gastroenteropathy due to Norovirus</note>
<note>Acute gastroenteropathy due to Norwalk-like agent</note>
</inclusionTerm>
</diag>
<diag>
<name>A08.19</name>
<desc>Acute gastroenteropathy due to other small round viruses</desc>
<inclusionTerm>
<note>Acute gastroenteropathy due to small round virus [SRV] NOS</note>
</inclusionTerm>
</diag>
</diag>
<diag>
<name>A08.2</name>
<desc>Adenoviral enteritis</desc>
</diag>
<diag>
<name>A08.3</name>
<desc>Other viral enteritis</desc>
<diag>
<name>A08.31</name>
<desc>Calicivirus enteritis</desc>
</diag>
<diag>
<name>A08.32</name>
<desc>Astrovirus enteritis</desc>
</diag>
<diag>
<name>A08.39</name>
<desc>Other viral enteritis</desc>
<inclusionTerm>
<note>Coxsackie virus enteritis</note>
<note>Echovirus enteritis</note>
<note>Enterovirus enteritis NEC</note>
<note>Torovirus enteritis</note>
</inclusionTerm>
</diag>
</diag>
</diag>
的diag
s的封裝在section
s,這是然後在chapter
s,這都是下root
。我所需的輸出是:
A08;Viral and other specified intestinal infections;
A08.0;Rotaviral enteritis;
A08.1;Acute gastroenteropathy due to Norwalk agent and other small round viruses;
A08.11;Acute gastroenteropathy due to Norwalk agent;Acute gastroenteropathy due to Norovirus Acute gastroenteropathy due to Norwalk-like agent
注意,當出口下inclusionTerm
任何note
s就被連接成一個領域。
這是我與現在的工作的XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="diag">
<xsl:apply-templates select="name" mode="print"/>;<xsl:apply-templates select="desc" mode="print"/>;<xsl:apply-templates select="inclusionTerm/note" mode="print"/>
</xsl:template>
</xsl:stylesheet>
它適用於拉出根diag
S(任何一個section
作爲其父)。我曾嘗試添加另一個apply-templates
來匹配嵌套的diag
,但它最終讓每個diag
及其所有diag
孩子變成一團糟。
現貨,謝謝! –