简体   繁体   English

如何从 xml 属性中获取 xslt 参数的值

[英]How do I get the value for a xslt parameter out of a xml attribute

How do I get the value for a xslt parameter out of a xml attribute?如何从 xml 属性中获取 xslt 参数的值? I have a xslt file, which transforms a dita map with 9 topicref into html sites.我有一个 xslt 文件,它将带有 9 个 topicref 的 dita map 转换为 html 个站点。

The topicref have attributes on their own and inside each file to filter, depending on the type of the product. topicref 有自己的属性和每个文件中的属性来过滤,这取决于产品的类型。

I want to make paramters in xslt so i can filter the transformation depending on the type of the product.我想在 xslt 中创建参数,以便我可以根据产品类型过滤转换。

How to I get the attribute as the value of the parameter and how do I filter the transformation depending on the paramets?如何获取属性作为参数的值以及如何根据参数过滤转换?

I tried this:我试过这个:

    <xsl:param name="Getriebe" select="doc('hausarbeit.ditamap')/map/topicref[@product]"/>
    <xsl:param name="Keyless" select="doc('hausarbeit.ditamap')/map/topicref[@otherprops]"/>

and this:和这个:

    <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>

this is the ditamap:这是 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>

this is the code to create the html sites:这是创建 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>

It looks as if看起来好像

<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>

should rather be应该是

<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>

which could be shortened to eg可以缩短为例如

<xsl:template match="@product[. = 'Schaltung']">
   <xsl:apply-templates/>
</xsl:template>

Only none of that does anything meaningful as <xsl:apply-templates/> processes the child nodes of the context node and as you match on an attribute and attributes don't have child nodes it is not clear what that code is supposed to achieve.只有这些都没有做任何有意义的事情,因为<xsl:apply-templates/>处理上下文节点的子节点,并且当您匹配属性并且属性没有子节点时,不清楚该代码应该实现什么.

It is also not clear what也不清楚是什么

<xsl:param name="Getriebe" select="doc('hausarbeit.ditamap')/map/topicref[@product]"/>

is supposed to do with the referenced topicref element as $Getriebe is not used anywhere.应该与引用的topicref元素有关,因为$Getriebe未在任何地方使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM