Re: [xsl] xsl grabbing specific data

Subject: Re: [xsl] xsl grabbing specific data
From: "cking" <cking@xxxxxxxxxx>
Date: Thu, 9 Sep 2004 10:04:32 +0200
Hi Dan,

Maybe you can create an additional xml-file, say 'files.xml':

    <files>
        <file>boot.ini</file>
        <file>compmgmt.msc</file>
        ...
    </files>

And then use

    <xsl:variable name="files" select="document('files.xml')/files/file"/> and
    <xsl:if test="$files[contains(file-acl/@name, .)]">

to extract only the files you want... something like

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

 <xsl:variable name="files" select="document('files.xml')/files/file"/>

 <xsl:template match="/">
  <list>
   <xsl:apply-templates select="//file-acl-list/file-acl"/>
   <!-- NOTE: if possible, pass absolute path rather than "//" -->
  </list>
 </xsl:template>

 <xsl:template match="file-acl">
  <xsl:if test="$files[contains(current()/@name, .)]">
   <xsl:variable name="filename">
    <xsl:call-template name="filename-from-path">
     <xsl:with-param name="name" select="@name"/>
    </xsl:call-template>
   </xsl:variable>
   <file name="{$filename}">
    <xsl:apply-templates select="ace"/>
   </file>
  </xsl:if>
 </xsl:template>

 <xsl:template match="ace">
  <xsl:if test="@is-grant = 'true'">
   <!-- or do whatever else to handle this -->
   <ace trustee="{@trustee}"/>
  </xsl:if>
 </xsl:template>

 <xsl:template name="filename-from-path">
  <xsl:param name="name"/>
  <xsl:choose>
   <xsl:when test="contains($name, '\')">
    <xsl:call-template name="filename-from-path">
     <xsl:with-param name="name" select="substring-after($name, '\')"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$name"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

</xsl:stylesheet>

HTH,
Anton Triest

Current Thread