[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Harry Liljestrvm <harry.liljestrom@xxxxxxxxxxxxx> kirjoitti:
Hi again,
Harry
Re: [xsl] Applying template with a variable
Subject: Re: [xsl] Applying template with a variable From: Harry Liljeström <harry.liljestrom@xxxxxxxxxxxxx> Date: Wed, 17 Jan 2007 14:27:45 +0200 (EET) |
Harry Liljestrvm <harry.liljestrom@xxxxxxxxxxxxx> kirjoitti:
Hi,match="authentication-object[type = 'plain-file']">.
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
context, than the authentication-object:s!
Note: The template with match //authentication/object is in different
select="/config/authentication-objects/authentication-object"/>
<xsl:variable name="locauthobjs"
<xsl:variable name="globauthobjs"
select="document('../etc/policyglobal.xml')/config/authentication-objects/aut hentication-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.]
string-length(substring-after($path,'cert//')) + 1"/><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[@name=$name] !=''"> <xsl:value-of select="$locauthobjs[@name=$name]"/> </xsl:when> <xsl:otherwise> <!-- It seems to exist in the global file!--> <xsl:value-of select="$globauthobjs[@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//')) - $totlen"/></xsl:variable> <xsl:variable name="cert_len"> <xsl:value-of select="string-length(substring-before($path, ' ')) +
string-length(substring-after($path,'priv//')) + 1)"/></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 -
<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.
priv//C:/Temp/Certs/priv-key1.prv</path>
<config> <authentication-objects> <authentication-object name="My_test_665_private_key"> <type>plain-file</type> <path>cert//C:/Temp/Certs/cert1.bin
some rule should appear here. --></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
<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
Hi again,
I changed my XSLT code to: <xsl:template match="//authentication/object"> <xsl:variable name="name" select="."/> <xsl:choose> <xsl:when test="$locauthobjs[@name=$name] !=''"> <xsl:apply-templates select="$locauthobjs[@name=$name]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="$globauthobjs[@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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Applying template with a vari, Harry Liljeström | Thread | Re: [xsl] Applying template with a , Abel Braaksma |
Re: [xsl] saxon xmlspy discrepancy , Colin Adams | Date | Re: [xsl] Applying template with a , Abel Braaksma |
Month |
Keywords