|
Subject: Re: [xsl] splitting multiple occurrences of an element within another element From: "Brian Benson" <bbenson@xxxxxxxxxxxx> Date: Wed, 24 Sep 2003 13:56:30 -0500 |
Mukul
Thanks for the help. I forgot to mention in my previous post that doclinks
are not always directly under a document. In fact they can be any number
of nested levels deep. The code that you sent gets the doclink info fine,
but does not return @form or @unid. Any other ideas.
Mukul Gandhi
<mukulgw3@xxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent by: cc:
owner-xsl-list@xxxxxxxxxxx Subject: Re: [xsl] splitting multiple occurrences of an element within another element
rrytech.com
09/24/2003 01:12 PM
Please respond to xsl-list
Hi Brian,
Please try the XSL --
<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/database">
<database>
<xsl:for-each select="document/doclink">
<document>
<form>
<xsl:value-of select="parent::document/@form" />
</form>
<unid>
<xsl:value-of
select="preceding-sibling::noteinfo[1]/@unid" />
</unid>
<doclink>
<xsl:value-of select="@document" />
</doclink>
</document>
</xsl:for-each>
</database>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
--- Brian Benson <bbenson@xxxxxxxxxxxx> wrote:
> I am very new to xsl and really struggling to get
> the results that I want.
>
> I am trying to convert an xml file that looks like
> this
> ====================
> <database>
> <document form='formname'>
> <noteinfo unid='abc'/>
> <doclink document='1'/>
> <doclink document='2'/>
> </document>
> </database>
>
> Into an xml file that looks like this
> =====================
> </database>
> <document>
> <form>formname</form>
> <unid>abc</unid>
> <doclink>1</doclink>
> </document>
>
> <document>
> <form>formname</form>
> <unid>abc</unid>
> <doclink>2</doclink>
> </document>
> </database>
>
>
> The xslt that I have so far works well, except for
> the following:
> 1) If there is more than one doclink in one
> document, they need to be split
> into multiple documents so that there is one doclink
> per document. The xsl
> below puts all doclinks in one document.
> 2) The form and unid attributes are output as
> attributes and they need to
> be converted to elements.
>
> I have been able to get both of the above to work,
> but not at the same
> time. Any help is appreciated.
>
> The xslt that I have so far looks like this:
> =====================
> <xsl:template match="/">
> <database>
> <xsl:apply-templates/>
> </database>
> </xsl:template>
>
> <xsl:template match="dxl:document">
> <document>
> <xsl:copy-of select="@form |
> dxl:noteinfo/@unid
> |.//dxl:doclink"/>
> </document>
>
> <xsl:apply-templates/>
> </xsl:template>
>
>
> <!-- remove all other text and attributes -->
> <xsl:template match ="text()|@*"></xsl:template>
>
> <!-- remove all documents with no doc links -->
> <xsl:template match
> ="dxl:document[not(.//dxl:doclink)]"></xsl:template>
>
>
>
>
>
> XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] splitting multiple occurr, Mukul Gandhi | Thread | RE: [xsl] splitting multiple occurr, Passin, Tom |
| RE: [xsl] splitting multiple occurr, Brian Benson | Date | RE: [xsl] splitting multiple occurr, Passin, Tom |
| Month |