Domanda

I'm trying to implement lookup table functionality in xslt. I've my lookup table in an external file at the same location as my XSL file. Here is my XSL, lookup table file content. When I run this I don't see any output except this inside the templatefield-names-table.xml Appreciate if someone could help me out in identifying the issue. Also, please share some examples using XSLT 2.0. I'm using XSLT 2.0 and my XSL library is saxon

XSL

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            exclude-result-prefixes="soap">

<xsl:output indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>

<!-- holds the path to field names mapping table -->
<xsl:variable name="field-names-table-path" select="'field-names-table.xml'" />
<!-- load the field names mapping table and store it in a variable -->
<xsl:variable name="field-names-table" select="document($field-names-table-path)"/>

<xsl:key name="field-name-lookup" match="name" use="@canonical"/>    

<!-- entry point template -->
<xsl:template match="/soap:Envelope/soap:Body" name="main">

    <xsl:value-of select="'inside the template'" />
    <xsl:value-of select="$field-names-table-path"/>
    <xsl:value-of select="$field-names-table"/>        
    <xsl:variable name="brand" select="'rml'"/>

    <xsl:value-of select="key('field-name-lookup','vat_total')" />
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()" />

field-names-table.xml

<?xml version="1.0" encoding="UTF-8"?>
<names>
  <name canonical="vat_total" rml="rml_vat_total"></name>
</names>

Thank you

È stato utile?

Soluzione

I think you want

<xsl:value-of select="key('field-name-lookup','vat_total', $field-names-table)/@rml" />

instead of

<xsl:value-of select="key('field-name-lookup','vat_total')" />
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top