🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: nl.comp.programmeren
Article #54

Re: xml naar xml transformeren

#54
From: Suzan Foster
Date: Thu, 28 Feb 2008 09:51
86 lines
3395 bytes
flor schreef:
> Hallo,
>
> Ik probeer om een xml bestand om te zetten in een anders gevormd xml 
> bestand.
> Dit schijnt relatief makkelijk te kunnen met xsl transformatie.
> Ik raak er echter maar niet uit.
> Het input bestand is als volgt gevormd:
>
>> <B T="D" N="Result">
>>    <B T="T" N="Subject">
>>       <B T="R">
>>          <B T="C" N="FirstName" V="voornaam"/>
>>          <B T="C" N="LastName" V="achternaam"/>
>>          <B T="C" N="BirthDate" V="1972-12-22 00:00:00"/>
>>          <B T="C" N="PersonalID" V="123"/>
>>       </B>
>>    </B>
>> </B>
>
> Nu wil ik dit omvormen naar iets als:
>
>> <Subject>
>> <Name>
>>    <FirstName>voornaam</FirstName>
>>    <LastName>achternaam</LastName>
>> </Name>
>> <DateOfBirth>22/12/1972</DateOfBirth>
>> <ID>123</ID>
>> </Subject>
>
> hoe moet dit?
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:strip-space elements="B"/>
    
  <xsl:template match="B">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="B[@N='Subject']">
    <Subject>
        <Name>
            <xsl:apply-templates select="//B[@N='FirstName']"/>
            <xsl:apply-templates select="//B[@N='LastName']"/>
        </Name>
        <xsl:apply-templates select="//B[@N='BirthDate']"/>
        <xsl:apply-templates select="//B[@N='PersonalID']"/>
    </Subject>
  </xsl:template>

  <xsl:template match="B[@N='FirstName']">
    <FirstName>
        <xsl:value-of select="@V"/>
    </FirstName>
  </xsl:template>

  <xsl:template match="B[@N='LastName']">
    <LastName>
        <xsl:value-of select="@V"/>
    </LastName>
  </xsl:template>

  <xsl:template match="B[@N='BirthDate']">
    <xsl:param name="date" select="substring-before(@V, ' ')"/>
    <xsl:param name="year" select="substring-before($date, '-')"/>
    <xsl:param name="month-and-day" select="substring-after($date, '-')"/>
    <xsl:param name="month" select="substring-before($month-and-day, '-')"/>
    <xsl:param name="day" select="substring-before($month-and-day, '-')"/>
    <DateOfBirth>
        <xsl:value-of select="concat($day, '/', $month, '/', $year)"/>
    </DateOfBirth>
  </xsl:template>

  <xsl:template match="B[@N='PersonalID']">
    <ID>
        <xsl:value-of select="@V"/>
    </ID>
  </xsl:template>
</xsl:stylesheet>

Ietsa siempel :oP

Groeten, su.
Technical Details
Message-ID: <47c6843b$0$14347$e4fe514c@news.xs4all.nl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!transit.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
References: <XWfxj.208175$TA1.37880@newsfet08.ams>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107324,deb01c5868a6cdc8
X-Google-Thread: fcea4,deb01c5868a6cdc8
X-Google-Attributes: gid107324,gidfcea4,public,usenet
X-Google-Language: DUTCH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!transit.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Date: Thu, 28 Feb 2008 10:51:57 +0100
From: Suzan Foster <su@islief.nl>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
Newsgroups: nl.comp.programmeren,be.comp.programming
Subject: Re: xml naar xml transformeren
References: <XWfxj.208175$TA1.37880@newsfet08.ams>
In-Reply-To: <XWfxj.208175$TA1.37880@newsfet08.ams>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 86
Message-ID: <47c6843b$0$14347$e4fe514c@news.xs4all.nl>
NNTP-Posting-Host: 193.173.220.65
X-Trace: 1204192315 news.xs4all.nl 14347 foz/[::ffff:193.173.220.65]:60086
X-Complaints-To: abuse@xs4all.nl