[英]How do I get the value for a xslt parameter out of a xml attribute
如何從 xml 屬性中獲取 xslt 參數的值? 我有一個 xslt 文件,它將帶有 9 個 topicref 的 dita map 轉換為 html 個站點。
topicref 有自己的屬性和每個文件中的屬性來過濾,這取決於產品的類型。
我想在 xslt 中創建參數,以便我可以根據產品類型過濾轉換。
如何獲取屬性作為參數的值以及如何根據參數過濾轉換?
我試過這個:
<xsl:param name="Getriebe" select="doc('hausarbeit.ditamap')/map/topicref[@product]"/>
<xsl:param name="Keyless" select="doc('hausarbeit.ditamap')/map/topicref[@otherprops]"/>
和這個:
<xsl:template match="@product">
<xsl:if test="Schaltung">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
<xsl:template match="@otherprops">
<xsl:if test="Key">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
這是 ditamap:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map xml:lang="de-DE" >
<title>VW Tiguan</title>
<topicref href="dita/ausstattungsmerkmale.dita"/>
<topicref href="dita/motor_anlassen_und_abstellen_kontrollleuchten.dita"/>
<topicref otherprops="Key" href="dita/zuendschloss.dita"/>
<topicref otherprops="Keyless" href="dita/starterknopf.dita"/>
<topicref href="dita/motor_anlassen.dita"/>
<topicref href="dita/motor_abstellen.dita"/>
<topicref href="dita/elektronische_wegfahrsperre.dita"/>
<topicref href="dita/pedale.dita"/>
<topicref product="Schaltung" href="dita/schaltgetriebe_gang_einlegen.dita"/>
<topicref product="Automatik" href="dita/dsg_gang_einlegen.dita"/>
</map>
這是創建 html 站點的代碼:
<xsl:for-each
select="doc('hausarbeit.ditamap')/map/topicref/document(@href)">
<xsl:result-document href="{//title}.html" method="html" version="5">
<html>
<head>
<link rel="stylesheet" href="Inhalt.css"/>
<title>
<xsl:value-of select="document(@href)//title"/>
</title>
</head>
<body>
<div class="HeadBlock">
<xsl:call-template name="Header"/>
<xsl:call-template name="Sidebar"/>
</div>
<div class="Inhalt">
<xsl:apply-templates/>
</div>
</body>
</html>
</xsl:result-document>
</xsl:for-each>
看起來好像
<xsl:template match="@product">
<xsl:if test="Schaltung">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
<xsl:template match="@otherprops">
<xsl:if test="Key">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
應該是
<xsl:template match="@product">
<xsl:if test=". = 'Schaltung'">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
<xsl:template match="@otherprops">
<xsl:if test=". = 'Key'">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
可以縮短為例如
<xsl:template match="@product[. = 'Schaltung']">
<xsl:apply-templates/>
</xsl:template>
只有這些都沒有做任何有意義的事情,因為<xsl:apply-templates/>
處理上下文節點的子節點,並且當您匹配屬性並且屬性沒有子節點時,不清楚該代碼應該實現什么.
也不清楚是什么
<xsl:param name="Getriebe" select="doc('hausarbeit.ditamap')/map/topicref[@product]"/>
應該與引用的topicref
元素有關,因為$Getriebe
未在任何地方使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.