我需要知道 XML 檔案是否具有 < ?xml-stylesheet type="text/xsl" href="recibo.xsl" 中的 href 屬性?> 確定它是哪種發票(在我的 XSLT 檔案中)。我花了很多時間搜索,但找不到任何有關它的資訊。甚至可以在 XSLT 中讀取/訪問這些屬性嗎?
uj5u.com熱心網友回復:
閱讀處理指令很容易:string(/processing-instruction('xml-stylesheet')). 但這不會決議其值中的“偽屬性”(type和href)。您必須自己做這件事,除非您的處理器提供了諸如saxon:get-pseudo-attribute.
uj5u.com熱心網友回復:
在 XSLT 3 中,您可以嘗試例如
<xsl:variable name="stylesheet-href" as="xs:string?" select="parse-xml-fragment('<pi ' || /processing-instruction('xml-stylesheet') || '/>')/pi/@href"/>
讀出xml-stylesheet處理指令節點并將其目標決議為您從中提取href偽屬性值的屬性。
請注意,document-uri(document(''))這也可能為您提供 XSLT 運行的樣式表 URI。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339836.html
