Print

Print


Mark,

Thank you for accurate analysis of what I was after and the
instructions for doing so. I did tweak it slightly, but got to what I
needed in the end. Your explanation was clear and very helpful.

Nathan


On Wed, Oct 9, 2013 at 11:11 AM, Custer, Mark <[log in to unmask]> wrote:
> Hi Nathan,
>
> Is this style sheet being used for HTML output?  If so, then the HTML should still render with a single space even if there are multiple spaces in the output, right?
>
> In any event, what you're describing could definitely be addressed by a transformation, but the way that you've changed the Cookbook style sheet isn't ideal since you've changed <xsl:apply-templates select="unittitle"/> to a value-of select statement. The problem here is that you're stripping the unittitle of any potential sub-elements, like title and emph, so those won't be processed if/when they occur.   So, it sounds to me like you want your style sheet to be permissive enough to handle the following cases:
>
> *       <unittitle>Title<unitdate>Date</unitdate></unittitle>
>
> *       <unittitle>Title             <unitdate>Date      </unitdate></unittitle>
>
> *       <unittitle>Title</unittitle>
> <unitdate>Date</unitdate>
>
> *       <unittitle>       <title>I'm a   title   title    </title> mixed content<unitdate>Date</unitdate>     </unittitle>
>
> I'm sure there's a better way to do this (and it really depends on the rest of your style sheet), but one possible option would be to do something like the following:
>
> <!- rather than the xsl:choose statement (assuming that you keep the named template as is) -->
>     <xsl:apply-templates select="unittitle"/>
>     <xsl:apply-templates select="unitdate"/>
>
> And then add a template like this, which will normalize all of your text nodes, but then add (or re-add) a space between any mixed-content elements:
>
>         <xsl:template match="text()">
>                 <xsl:if test="preceding-sibling::*">
>                         <xsl:text>&#x20;</xsl:text>
>                 </xsl:if>
>                 <xsl:copy-of select="normalize-space()"/>
>                 <xsl:if test="following-sibling::*">
>                         <xsl:text>&#x20;</xsl:text>
>                 </xsl:if>
>         </xsl:template>
>
> I haven't tested this with your style sheet, of course, but something like this should work.   I hope that helps, or at least puts you on the right path,
>
> Mark
>
>
>
> -----Original Message-----
> From: Encoded Archival Description List [mailto:[log in to unmask]] On Behalf Of Nathan Tallman
> Sent: Wednesday, October 09, 2013 10:35 AM
> To: [log in to unmask]
> Subject: Re: XSLT Question Regarding Unittitle
>
> Mark,
>
> I've run into a snag. Using mode and the template rule you suggested, child elements of unittitle, other than unitdate, are not being processed. Mostly this is noticeable with title tags, as italics and quotes are missing.
>
> Any suggestions?
>
> Nathan
>
> On Tue, Oct 8, 2013 at 10:55 PM, Mark Carlson <[log in to unmask]> wrote:
>> Hello
>>
>> Alter this line to add a mode attribute
>>
>> <xsl:apply-templates select="unittitle/text() |
>> unittitle/*[not(self::unitdate)]" mode="unittitle"/>
>>
>> Then add this template rule:
>>
>> <xsl:template match="text()" mode="unittitle">
>>
>>         <xsl:value-of select="normalize-space(.)"/> </xsl:template>
>>
>> Not tested.
>>
>> Mark
>>
>>
>> On Tue, 8 Oct 2013, Nathan Tallman wrote:
>>
>>> 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
>>>
>>>
>>>
>>>
>>