[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Applying template with a variable

Subject: Re: Applying template with a variable
From: Harry Liljeström <harry.liljestrom@xxxxxxxxxxxxx>
Date: Wed, 17 Jan 2007 14:27:45 +0200 (EET)
xsl variables in apply templates
Harry Liljestrvm <harry.liljestrom@xxxxxxxxxxxxx> 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/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.]
-->
   <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//')) + 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


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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.