我想制作一个样式表,并使用xslt/xpath循环遍历我的树,但我不能用这个xml做基础工作。这个xml可用于xslt/xpath吗?
我想按examId循环通过考试,并检查examType
<data>
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="planCode">01267 COE-EN/2014-08-01</string>
<string key="planName">01267 COE-EN</string>
<map key="exams">
<string key="examId">00131105</string>
<string key="examType">Kwalificatie</string>
<string key="examName">90404 S Interact. vormgev.</string>
<array key="exams">
<map>
<string key="examId">00162650</string>
<string key="examType">Kwalificatie</string>
<string key="examName">90402 S Interact. vormgev.</string>
</map>
<map>
<string key="examId">00162640</string>
<string key="examType">Kwalificatie</string>
<string key="examName">90403 S Interact. vormgev.</string>
</map>
</array>
</map>
</map>
</data>
XSLT for what its worth...
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="/data/map/string/@key ">
<test>Test</test>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Edit;
The answer helped me a lot and I could finally address the elements and attributes. I think it was because I didnt use the namespace xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
-----------
给定map元素上的命名空间声明,该路径只有在使用通配符/data/*:map/*:string/@key
,或者在样式表中声明例如xmlns:fn="http://www.w3.org/2005/xpath-functions"
并使用例如/data/fn:map/fn:string/@key
,或者在格式表中声明xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
并使用/*:data/map/string/@key
或/*/map/string/@key
时才能工作。
要使其变平,请使用//
作为/data//*:string[@key = 'examType']