Re: Extend XML file attributes using XSLT

Christian Rühl <[email protected]> Fri, 09 Nov 2007 13:04:56 -0000
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization http://groups.google.com
Message-ID <[email protected]>
On 9 Nov., 10:49, "Anthony Jones" <[email protected]> wrote:
> "Christian Rühl" <[email protected]> wrote in message
>
> news:[email protected]...
>
>
>
> > Hi folks!
>
> > I have a little noob problem here with XSLT. I have a XML file that
> > looks like this:
>
> > <archiveFiles>
> >    <module path="c:/temp/module_m17_blabla.tmp"/>
> >    <module path="c:/temp/module_m34_blabla.tmp"/>
> >    ...
> >    <moduleAddition path="c:/temp/moduleaddition_m17.tmp"/>
> >    ...
> > </archiveFiles>
>
> > What I want to do now is the following:
>
> > 1.) Copy name part of filename in <module>
> > ---------------------------------------------
> > I want to copy that module name part and add it to a new attribute
> > called "name". How should I do this? The name of each module comes
> > right after module_ in the path-attributes.
>
> > 2.) Reference additional information to these modules
> > ---------------------------------------------
> > Finally another attribute "addition" should be added to each <module>
> > when there is a <moduleAddition> node with the same module name in its
> > "path" attribute. So that the outcome of the upper XML file looks like
> > this:
>
> > <archiveFiles>
> >    <module name ="m17" path="c:/temp/module_m17_blabla.tmp"
> > additon="c:/temp/moduleaddition_m17.tmp"/>
> >    <module name ="m34" path="c:/temp/module_m34_blabla.tmp"/>
> >    ...
> > </archiveFiles>
>
> > I really hope you can help me. I never worked with XSLT before and I
> > couldn't find the right hints and/or tutorials yet. :(
>
> > Thanks a lot in advance!
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>  <xsl:output method="xml" indent="yes"/>
>  <xsl:key name="additions" match="moduleAddition"
> use="substring-before(substring-after(@path, 'moduleaddition_'), '.tmp')" />
>
>  <xsl:template match="/archiveFiles">
>    <archiveFiles>
>    <xsl:for-each select="module">
>     <xsl:variable name="name"
> select="substring-before(substring-after(@path, 'module_'), '_')" />
>     <xsl:variable name="addition" select="key('additions', $name)" />
>     <module name="{$name}" path="{@path}">
>      <xsl:if test="$addition">
>       <xsl:attribute name="addition"><xsl:value-of select="$addition/@path"
> /></xsl:attribute>
>      </xsl:if>
>     </module>
>    </xsl:for-each>
>    </archiveFiles>
>  </xsl:template>
>
> </xsl:stylesheet>
>
> --
> Anthony Jones - MVP ASP/ASP.NET

A dream! Exactly what I was looking for! Thank you so much! :)

_______________________________________________
dev-tech-xslt mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xslt