Harry Liljeström <harry(_dot_)liljestrom(_at_)saunalahti(_dot_)fi> kirjoitti:
Hi,
Is it possible in apply of template do variable selection in XSLT 1.0?
1. The variable authobj consists of authentication-object node.
2. <xsl:apply-templates select="$authobj"/> should launch the <xsl:template
match="authentication-object[type = 'plain-file']">.
Note: The template with match //authentication/object is in different context,
than the authentication-object:s!
<xsl:variable name="locauthobjs"
select="/config/authentication-objects/authentication-object"/>
<xsl:variable name="globauthobjs"
select="document('../etc/policyglobal.xml')/config/authentication-objects/authentication-object"/>
<xsl:template match="//authentication/object">
<xsl:variable name="authobj">
<xsl:call-template name="authobjbyname">
<xsl:with-param name="name" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates select="$authobj"/><!-- [1.] -->
</xsl:template>
<xsl:template match="authentication-object[type = 'plain-file']"><!-- [2.] -->
<xsl:variable name="keyfiles">
<xsl:call-template name="key_file">
<xsl:with-param name="path" select="path"/>
</xsl:call-template>
</xsl:variable>
<exteranal-key type="{'software'}" init-info="{$keyfiles}"/>
</xsl:template>
<xsl:template name="authobjbyname">
<xsl:param name="name"/>
<xsl:if test="$name !=''">
<xsl:choose>
<!-- Test if it exists in the local file? -->
<xsl:when test="$locauthobjs[(_at_)name=$name] !=''">
<xsl:value-of select="$locauthobjs[(_at_)name=$name]"/>
</xsl:when>
<xsl:otherwise>
<!-- It seems to exist in the global file!-->
<xsl:value-of select="$globauthobjs[(_at_)name=$name]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="key_file">
<xsl:param name="path"/>
<xsl:variable name="totlen">
<xsl:value-of select="string-length($path)"/>
</xsl:variable>
<xsl:if test="$totlen > 0">
<xsl:variable name="cert_pos">
<xsl:value-of select="$totlen - string-length(substring-after($path,'cert//'))
+ 1"/>
</xsl:variable>
<xsl:variable name="cert_len">
<xsl:value-of select="string-length(substring-before($path, ' ')) +
string-length(substring-after($path,'cert//')) - $totlen"/>
</xsl:variable>
<xsl:value-of select="'key_file('"/>
<xsl:value-of select="substring($path, $cert_pos, $cert_len)"/>
<xsl:value-of select="','"/>
<xsl:value-of select="substring($path, $totlen -
string-length(substring-after($path,'priv//')) + 1)"/>
<xsl:value-of select="')'"/>
</xsl:if>
</xsl:template>
Here below is a snippet from the input file. There can also exists authentication-object:s in
policyglobal.xml file, thats why <xsl:template name="authobjbyname"> is needed.
<config>
<authentication-objects>
<authentication-object name="My_test_665_private_key">
<type>plain-file</type>
<path>cert//C:/Temp/Certs/cert1.bin priv//C:/Temp/Certs/priv-key1.prv</path>
</authentication-object>
<authentication-object name="MyTestProfileSecret">
<type>pre-shared-key</type>
<path>hoobar</path>
</authentication-object>
<authentication-object name="NewTestKey">
<type>pre-shared-key</type>
<path>funny_hey</path>
</authentication-object>
</authentication-objects>
<policy-rules>
<ipsec-rules>
<rule name="CertificateAuthentication">
<authentication>
<object>
My_test_665_private_key
</object>
</authentication>
</rule>
<!-- There exists several rules here! -->
</ipsec-rules>
</policy-rules>
</config>
Desired output:
<!-- Those authentication-objects with type = 'plain-file' which are used in some
rule should appear here. -->
<exteranal-key type="software"
init-info="key_file(C:/Temp/Certs/cert1.bin,C:/Temp/Certs/priv-key1.prv)"/>
Hopefully you get the point.
Harry
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
Hi again,
I changed my XSLT code to:
<xsl:template match="//authentication/object">
<xsl:variable name="name" select="."/>
<xsl:choose>
<xsl:when test="$locauthobjs[(_at_)name=$name] !=''">
<xsl:apply-templates select="$locauthobjs[(_at_)name=$name]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$globauthobjs[(_at_)name=$name]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
so <xsl:call-template name="authobjbyname"> wasn't needed anymore. This seems
to work. For me it seems that in XSLT 1.0 variables can't contain node-sets!
Harry
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--