简体   繁体   中英

XSL. Passing param in string

Here is my XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="RSA-InsurerID"/>
<xsl:param name="RSA-schema-version"/>

<xsl:template match="/">
    <rsa:DriverStatusRequest xmlns:rsa="com/rsa/eosago/schema-"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <InsurerID>
            <xsl:value-of select="$RSA-InsurerID"
                          xmlns:ns2="com/rsa/eosago/schema-"/>
        </InsurerID>
        <IDCheckDriver>
            <xsl:value-of select="ns2:DriverResponse/IDCheckDriver"
                          xmlns:ns2="com/rsa/eosago/schema-"/>
        </IDCheckDriver>
    </rsa:DriverStatusRequest>
</xsl:template>

These two params values are passed via Apache Camel.

The question is how to pass and concat the param <xsl:param name="RSA-schema-version"/> with xmlns:rsa="com/rsa/eosago/schema-" ?

I got my <xsl:param name="RSA-InsurerID"/> with <xsl:value-of select="$RSA-InsurerID" , but i have no idea how to pass it to the value text.

I expect this output:

<?xml version="1.0" encoding="UTF-8"?>
<rsa:DriverStatusRequest xmlns:rsa="com/rsa/eosago/schema-1.2" 
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InsurerID>18800000</InsurerID>
<IDCheckDriver/>
</rsa:DriverStatusRequest>

Big thanks!

Try

<InsurerID>
            <xsl:value-of select="$RSA-InsurerID"
                          xmlns:ns2="com/rsa/eosago/schema-{$RSA-schema-version}"/>

Seems what you try to do is to generate a namespaces dynamically at run time. For example have a look to this or this answers. And try:

<xsl:template match="/">
    <xsl:element name="rsa:DriverStatusRequest" namespace="com/rsa/eosago/schema-{$RSA-schema-version}" >
        <InsurerID>
            <xsl:value-of select="$RSA-InsurerID" />
        </InsurerID>
    </xsl:element>
</xsl:template>

Which will generate:

<rsa:DriverStatusRequest xmlns:rsa="com/rsa/eosago/schema-1.2">
    <InsurerID>18800000</InsurerID>
</rsa:DriverStatusRequest>

But I assume there will be loot more problems coming up.

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