xsl-list
[Top] [All Lists]

Re: xsl grabbing specific data

2004-09-09 07:38:31
Anton,

Thank you so much, looks like I have a lot to learn.
From your example I have a much better understanding
of where I need to go. Only question I have now is say
that an xml has two identical trees, Like

<xml>
  <name value="dan">
  <name value="dan">
</xml>

Is there a way to stop the duplicaes during the
transform. I ran your transform and low and behold
boot.ini came to my results like above. Once again
thanks for the help.

Dan Sherman


--- cking <cking(_at_)telenet(_dot_)be> wrote:

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="{(_at_)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


--+------------------------------------------------------------------
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>
--+--





        
                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail