0
由於xmlns,下面的xml不能轉換,我嘗試了沒有xmlns,它按預期工作。但我正在接受xmlns的輸入。請建議我如何克服它。由於xmlns,無法轉換xml
要求:從xml中檢索productBenefitHeaders。
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<productData xmlns="http://www.example.org/consolidated">
<productResponse>
<product>
<status>
<isError>false</isError>
</status>
<productBenefit>
<productBenefitCategory>CARDs</productBenefitCategory>
<productBenefitId>12AA</productBenefitId>
<productBenefitHeader>Philips</productBenefitHeader>
</productBenefit>
<productBenefit>
<productBenefitCategory>CARDs</productBenefitCategory>
<productBenefitId>12AB</productBenefitId>
<productBenefitHeader>Samsung</productBenefitHeader>
</productBenefit>
</product>
</productResponse>
<productData>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="UTF-8" omit-xml-declaration="no"/>
<xsl:template match="/">
<xsl:for-each select="productData/productResponse/product/productBenefit">
<xsl:value-of select="productBenefitHeader"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
嘗試在網站上搜索'default namespaces'。 –
請參閱(例如):http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 –