Re: [xsl] value-of select problem (XSLT 2.0 solution)

Subject: Re: [xsl] value-of select problem (XSLT 2.0 solution)
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Tue, 15 Aug 2006 17:25:43 -0500
If you can use XSLT 2.0, this is an easy problem to solve. Here's how.

I made the following XML file from your sample input:

<?xml version="1.0" encoding="UTF-8"?>


and wrote the following transform for it:

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"

<xsl:output method="xml" indent="yes" />

  <xsl:template match="/">
      <xsl:for-each-group select="author" group-starting-with="authorFname">
        <xsl:apply-templates select="current-group()"/>

  <xsl:template match="authorFname">
    <FirstName><xsl:value-of select="."/></FirstName>

  <xsl:template match="authorMname">
    <MiddleName><xsl:value-of select="."/></MiddleName>

  <xsl:template match="authorLname">
    <LastName><xsl:value-of select="."/></LastName>

  <xsl:template match="authorDegree">
    <Degree><xsl:value-of select="."/></Degree>

  <!-- Note: The default template is handling the text nodes that contain
the punctuation -->


and got the following output (from Saxon 8):

<?xml version="1.0" encoding="UTF-8"?>
   <LastName>Dai</LastName>, <Degree>MD</Degree>;

Jay Bryant
Bryant Communication Services
----- Original Message ----- 
From: <cchelius@xxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, August 15, 2006 4:35 PM
Subject: [xsl] value-of select problem

> I have included a snippet from my xslt that I am having difficulties with.
> My source XML can contain several authors names but those names don't have
> to contain a middle name. The problem with my xslt is that when an author
> doesn't contain a middle name it will pull the middle name from the next
> author after it. Obviously this is no good as it creates a name that is
> incorrect. I'm not sure how to tell the xslt that if there is no middle
> name not to grab <authorMname from the next author. Any ideas?
> XML Code Sample:
> <author><authorFname>John</authorFname>
>             <authorLname>Dai</authorLname>,
> XSLT Sample:
>   <xsl:for-each select="Story/author/authorFname">
>                         <!-- Adjusted to allow for multiple authors -->
>                         <Author>
>                             <FirstName>
>                                 <xsl:value-of select="."/>
>                             </FirstName>
>                             <MiddleName>
>                                 <xsl:value-of
> select="following-sibling::authorMname[1]"/>
>                             </MiddleName>
>                             <LastName>
>                                 <xsl:value-of
> select="following-sibling::authorLname[1]"/>
>                             </LastName>
>                             <Suffix>
>                                 <xsl:value-of
> select="following-sibling::authorSuffix[1]"/>
>                             </Suffix>
>                             <Affiliation>
>                                 <xsl:value-of
> select="following-sibling::authorAffiliation[1]"/>
>                             </Affiliation>
>                         </Author>
>                     </xsl:for-each>

Current Thread