Print

Print


Out of curiosity, what's the benefit of using modes -- couldn't you just put those lines right there in the unittitle code block?

Michele

________________________________
From: Encoded Archival Description List [[log in to unmask]] on behalf of Mike Ferrando [[log in to unmask]]
Sent: Tuesday, October 08, 2013 5:39 PM
To: [log in to unmask]
Subject: Re: XSLT Question Regarding Unittitle

Nathan,
Here is my take on your question.
You want to normalize space in the unittitle element whitespace, except when there is a unitdate.
The difficult part of this is that unittitle is an element that should be in the xsl:preserve-space list.
This means that unittitle is an element where whitespace is going to be respected by the stylesheet.
The spacing will be respected, but the hardreturns and tabs will not be rendered when displayed by other output like html (of course your ccs/json could change that default for your output).
THE REAL ISSUE is simply that there may be other child elements of unittitle other than unitdate that have will present whitespace issues.

I think you can safely remove double spaces, hardreturns, and tabs.

XSLT works better when we let it work.

So, I would do the following:
<xsl:choose>
<xsl:when test="count(unittitle/*)!=0">
  <xsl:apply-templates select="unittitle" mode="clean_up_this_unittitle_whitespace"/>
</xsl:when>
<xsl:otherwise>
    <xsl:apply-template select="unittitle"/>
</xsl:otherwise>
</xsl:choose>

<xsl:template match="*" mode="clean_up_this_unittitle_whitespace">
    <xsl:apply-templates select="@* | *"/>
    <xsl:apply-templates select="text()" mode="clean_up_unittitle_whitespace_text"/>
</xsl:template>

<xsl:template match="text()" mode="clean_up_unittitle_whitespace_text">
    <xsl:variable name="str" select="normalize-space(.)"/>
    <xsl:value-of select="translate(translate(translate($str, '&#x9;'  '), '&#xA;', ' '), '  ', ' ')"/>
</xsl:template>

-mike


________________________________
From: Nathan Tallman <[log in to unmask]>
To: [log in to unmask]
Sent: Tuesday, October 8, 2013 4:03 PM
Subject: XSLT Question Regarding Unittitle

Hi all,

I'm trying to adjust a snippet from a cookbook stylesheet. Here's what is is now:

     <xsl:choose>
         <!--This code processes the elements when unitdate is a child of unittitle.-->
         <xsl:when test="unittitle/unitdate">
            <xsl:apply-templates select="unittitle/text() | unittitle/*[not(self::unitdate)]"/>
            <xsl:for-each select="unittitle/unitdate">
               <xsl:text> </xsl:text>
               <xsl:value-of select="normalize-space(.)"/>
            </xsl:for-each>
         </xsl:when>
         <!--This code process the elements when unitdate is not a child of untititle-->
         <xsl:otherwise>
            <xsl:value-of select="normalize-space(unittitle)"/>
            <xsl:for-each select="unitdate">
               <xsl:text> </xsl:text>
               <xsl:value-of select="normalize-space(.)"/>
            </xsl:for-each>
         </xsl:otherwise>
      </xsl:choose>

What I'd like to do is to normalize the space of everything in unittitle, except unitdate, when unitdate is a child of unittitle. Normalizing a plain-old unittitle is easy enough, but I run into problems when unittitle contain child elements, other than unitdate (<title>, for example). I wish I could just add normalize-space() to the apply-templates xpath.

Can anyone make any suggestions? Seems like this would've been done before.

Thanks,
Nathan