[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:for-each in Corresp Tag

Subject: Re: xsl:for-each in Corresp Tag
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Feb 2020 23:06:22 -0000
Re:  xsl:for-each in Corresp Tag
Hi Byomokesh,

You request suggestions but so far you aren't following our advice.
You have not even indented your code for legibility, as requested. One
reason this list exists is that all its contributors follow the list
guidelines, posted monthly.
(https://www.mulberrytech.com/xsl/xsl-list/) Please read and follow
the instructions on how to ask for help -- it helps us to help you!

Moving forward, there is a deeper problem, which is that your code
will break on even simple cases, even apart from the special problem
of your <institution> elements.

For example, what do you expect to see as a result from processing this?

<corresp><label>To</label>A Writer, ;
<email>awriter@xxxxxxxxxxx</email>, <addr-line
content-type="street">100 Some St</addr-line>,
<country>USA</country></corresp>

Your XSLT will rearrange these elements. Would that be a correct result?

I ask this because if you aim to rearrange the elements in the output
(not just rename things), one approach is called for. If you do not
wish them to be rearranged (only renamed and grouped), a different
approach is called for.

Please clarify.

Thanks, Wendell

On Thu, Feb 20, 2020 at 10:46 AM Byomokesh Sahoo
sahoo.byomokesh@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
>
> Hi,
>
> Here my xml and xslt
>
> XML
> <article>
> <corresp><label>To</label> Anne Marie Darling, <institution
content-type="department">Department of Epidemiology</institution>,
<institution>Boston University</institution>, <addr-line
content-type="street">715 Albany Street</addr-line>, <country>USA</country>;
<email>amdarlin@xxxxxx</email></corresp>
>
> <corresp><label>To</label> Christle; <institution
content-type="department">Department of Epidemiology</institution>, <addr-line
content-type="postal-code">02118</addr-line>, <country>USA</country>;
<email>amdarlin@xxxxxx</email></corresp>
>
> <corresp><label>To</label> Anne Marie Darling; <institution>Department of
Epidemiology</institution>, <addr-line content-type="city">Takd</addr-line>,
<country>USA</country>; <email>amdarlin@xxxxxx</email></corresp>
>
> <corresp>Joanne Lawrence, Association of British Neurologists, Ormond House,
27 Boswell Street, London WC1N 3JZ, UK;
<email>joanne.lawrence@xxxxxxxxxx</email></corresp>
> </article>
>
> my XSLT
>
> <xsl:template match="article">
> <xsl:element name="article">
>
> <xsl:apply-templates/>
> </xsl:element>
> </xsl:template>
>
> <xsl:template match="corresp">
> <xsl:element name="corresp">
>
> <xsl:for-each select="label">
> <xsl:element name="x">
> <xsl:value-of select="."/>
> </xsl:element>
> <xsl:text>, </xsl:text>
> </xsl:for-each>
> <institution>
> <xsl:for-each select="institution">
> <xsl:choose>
> <xsl:when test="@content-type='department'">
>
> <xsl:element name="department">
> <xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
> </xsl:element>
> <xsl:text>, </xsl:text>
> </xsl:when>
> <xsl:otherwise>
> <xsl:element name="institution-name">
> <xsl:value-of select="."/>
> </xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each>
> </institution>
> <xsl:text>, </xsl:text>
>
> <xsl:for-each select="addr-line">
> <xsl:choose>
> <xsl:when test="@content-type='street'">
> <xsl:element name="street">
> <xsl:value-of select="."/>
> </xsl:element>
> <xsl:text>, </xsl:text>
> </xsl:when>
> <xsl:when test="@content-type='postal-code'">
> <xsl:element name="postal-code">
> <xsl:value-of select="."/>
> </xsl:element>
> <xsl:text>, </xsl:text>
> </xsl:when>
> </xsl:choose>
> </xsl:for-each>
> <xsl:for-each select="country">
> <xsl:element name="country">
> <xsl:value-of select="."/>
> </xsl:element>
> <xsl:text>; </xsl:text>
> </xsl:for-each>
> <xsl:for-each select="email">
> <xsl:element name="email">
> <xsl:value-of select="."/>
> </xsl:element>
> </xsl:for-each>
> </xsl:element>
> </xsl:template>
>
> Expected Output
>
> <article>
> <corresp><x>To</x> Anne Marie Darling, <institution><department>Department
of Epidemiology</department>, <institution-name>Boston
University</institution-name></institution>, <street>715 Albany
Street</street>, <country>USA</country>;
<email>amdarlin@xxxxxx</email></corresp>
>
> <corresp><x>To</x> Christle; <institution><department>Department of
Epidemiology</department></institution>, <addr-line
content-type="postal-code">02118</addr-line>, <country>USA</country>;
<email>amdarlin@xxxxxx</email></corresp>
>
> <corresp><x>To</x> Anne Marie Darling;
<institution><institution-name>Department of
Epidemiology</institution-name></institution>, <city>Takd</city>,
<country>USA</country>; <email>amdarlin@xxxxxx</email></corresp>
>
> <corresp>Joanne Lawrence, Association of British Neurologists, Ormond House,
27 Boswell Street, London WC1N 3JZ, UK;
<email>joanne.lawrence@xxxxxxxxxx</email></corresp>
> </article>
>
> Please suggest.
>
> thanks
> Byomokesh
> XSL-List info and archive
> EasyUnsubscribe (by email)



--
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.