0
我越來越瘋狂。我只想檢索我的XML中的幾個值:與我的XSLT轉換匹配錯誤
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SearchDocumentResponse xmlns="http://axa.fr/gedald/2010/11">
<SearchDocumentResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<DocumentCollection>
<document>
<ObjectStore i:nil="true"/>
<DocId>{1DC43D04-2541-459C-83A7-BA6A761C64B5}</DocId>
<IndexCollection>
<index>
<IndexId>P001</IndexId>
<Value>OBJ002301</Value>
</index>
<index>
<IndexId>P002</IndexId>
<Value>15/11/2013 13:00:00</Value>
</index>
</IndexCollection>
</document>
</DocumentCollection>
<Message i:nil="true"/>
<NbDocument>7</NbDocument>
<Result>OK</Result>
</SearchDocumentResult>
</SearchDocumentResponse>
</s:Body>
</s:Envelope>
無論我嘗試作爲XSL文件,我都無法訪問內容。有時我會收到所有標籤內容。但從來沒有我想要的。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="s:Envelope/s:Body/SearchDocumentResponse/SearchDocumentResult/DocumentCollection/document/IndexCollection">
<html>
<body>
<xsl:value-of select="DocId"/>
<xsl:for-each select="index">
<ul>
<li><xsl:value-of select="IndexId"/></li>
<li><xsl:value-of select="Value"/></li>
</ul>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
完美。但我仍然不明白它是如何工作的...爲什麼我不能在SearchDocumentResponse之前放置axa,而不是在XML中? –
@TDLemon,因爲這是XML名稱空間的工作方式 - XML中的'xmlns =「http://axa.fr/gedald/2010/11」'將該元素及其所有後代元素與未加前綴的名稱放在' http:// axa.fr/gedald/2010/11'命名空間。要匹配XPath 1.0中的名稱空間節點,您必須使用前綴。 –
@TDLemon XSLT/XPath不關心原始XML文檔使用哪些前綴或默認命名空間聲明,重要的是您在stylesheet_中爲正確的命名空間URI聲明瞭前綴綁定,然後一致地使用這些前綴。我本來可以使用'xmlns:blah =「http://axa.fr/gedald/2010/11」'和'blah:SearchDocumentResponse',這樣可以很好地工作。 –