简体   繁体   中英

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? I have a xslt file, which transforms a dita map with 9 topicref into html sites.

The topicref have attributes on their own and inside each file to filter, depending on the type of the product.

I want to make paramters in xslt so i can filter the transformation depending on the type of the product.

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:

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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