這是我要遍歷的 XML,按<SUBJECT>. 我已經能夠做到這一點,但我需要應用一個條件來檢查<DocumentList>節點是否存在,如果不存在,則顯示“未找到資料”。此外,它還采用了我不想要的資料,如下面的螢屏截圖:
<KnowledgeBase>
<DocumentCount>8</DocumentCount>
<CountOnly>false</CountOnly>
<DocumentList>
<Document Identifier="428B474B-C016-4726-9325-20BC8B754427">
<SUBJECT>Bariatric Surgery Coding Guidelines</SUBJECT>
</Document>
<Document Identifier="261489E7-14E0-43CF-9909-6892A84D4BEA">
<SUBJECT>Bariatric Surgery Coding Guidelines</SUBJECT>
</Document>
<Document Identifier="1C336836-A5BB-424F-8A43-9BDD52A5BE9D">
<SUBJECT>Bariatric Surgery Coverage R2</SUBJECT>
</Document>
<Document Identifier="65E77B48-E88B-4AAF-B0A6-ED14BD028905">
<SUBJECT>Billing and Coding: Bariatric Surgery Coverage</SUBJECT>
</Document>
</DocumentList>
</KnowledgeBaseAdvancedSearchResponse>
XSLT 我試過:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:key name="groups" match="//KnowledgeBaseAdvancedSearchResponse/DocumentList/Document" use="SUBJECT" />
<xsl:template match="//KnowledgeBaseAdvancedSearchResponse/DocumentList">
<xsl:apply-templates select="Document[generate-id() = generate-id(key('groups', SUBJECT)[1])]" />
</xsl:template>
<xsl:template match="Document">
<h1><xsl:value-of select="SUBJECT" /></h1>
</xsl:template>
</xsl:stylesheet>
我想要類似于對相同資料進行分組的 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//KnowledgeBaseAdvancedSearchResponse/DocumentList">
<xsl:for-each select="//DocumentList/Document">
<h1><xsl:value-of select="SUBJECT" /></h1>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>No policy edits for the selected Payor/State.</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="//Errors">There were errors.</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
uj5u.com熱心網友回復:
我需要應用一個條件來檢查
<DocumentList>節點是否存在,如果不存在,則顯示“未找到資料”。
使用<xsl:apply-templates>和兩個不同的模板。一個匹配<KnowledgeBaseAdvancedSearchResponse>具有<DocumentList>(和<Document>),另一個匹配所有其他情況。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:key name="groups" match="Document" use="SUBJECT" />
<xsl:template match="/">
<xsl:apply-templates select="KnowledgeBaseAdvancedSearchResponse" />
</xsl:template>
<xsl:template match="KnowledgeBaseAdvancedSearchResponse[DocumentList/Document]">
<xsl:apply-templates select="DocumentList/Document[generate-id() = generate-id(key('groups', SUBJECT))]" />
</xsl:template>
<xsl:template match="KnowledgeBaseAdvancedSearchResponse">
<h1>No Data Found</h1>
</xsl:template>
<xsl:template match="Document">
<h1><xsl:value-of select="SUBJECT" /></h1>
</xsl:template>
</xsl:stylesheet>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/334359.html
上一篇:JetpackCompose:使父級外部的偏移影像可見
下一篇:在php中從xml中檢索密鑰
