After wrapping the entire sequence with <xsl:for-each select="doc:metadata/doc:element[@name='dc']">, perhaps another option is to wrap the entire "dc.publication fields to dc.identifier" in a for-each for doc:element[@name='publication'], create string variables for the values instead of using <xsl:text> so you can use concat(), then nest if-then-else for these scenarios:
If the volume element is not equal to empty then...
If the issue element is not equal to empty then return "publication name" Vol. "publication volume" Issue "publication issue"
Else (if the issue element is equal to empty) return "publication name" Vol. "publication volume"
Else (if the volume element is equal to empty)...
If the issue element is not equal to empty then return "publication name" Issue "publication issue"
Else (if the issue element is equal to empty) return "publication name" Vol.
I don't have the source metadata to test this, but hopefully this is enough to get the idea.
<xsl:template match="/">
<xsl:for-each select="doc:metadata/doc:element[@name='dc']">
<!-- dc.identifier -->
<xsl:for-each
select="doc:element[@name='identifier']/doc:element/doc:field[@name='value']">
<dc:identifier>
<xsl:value-of select="."/>
</dc:identifier>
</xsl:for-each>
<!-- dc.publication fields to dc.identifier -->
<xsl:for-each select="doc:element[@name='publication']">
<xsl:variable name="pub_name" as="xs:string"
select="doc:element[@name='name']/doc:element/doc:field[@name='value']"/>
<xsl:variable name="pub_vol" as="xs:string"
select="doc:element[@name='volume']/doc:element/doc:field[@name='value']"/>
<xsl:variable name="pub_issue" as="xs:string"
select="doc:element[@name='issue']/doc:element/doc:field[@name='value']"/>
<dc:identifier>
<xsl:value-of
select="
if (doc:element[@name='volume']/doc:element/doc:field[@name='value'] ne '') then
if (doc:element[@name='issue']/doc:element/doc:field[@name='value'] ne '') then concat($pub_name,' Vol. ', $pub_vol,' Issue ', $pub_issue) else
concat($pub_name,' Vol. ', $pub_vol)
else
if (doc:element[@name='issue']/doc:element/doc:field[@name='value'] ne '') then concat($pub_name,' Issue ', $pub_issue)
else $pub_name
"/>
</dc:identifier>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
Hope this helps,
Annie
Margaret “Annie” Glerum
Head of Complex Cataloging
Department of Cataloging & Description
Division of Special Collections & Archives
Florida State University Libraries
850-644-4839
[log in to unmask]
-----Original Message-----
From: Code for Libraries [mailto:[log in to unmask]] On Behalf Of Ethan Gruber
Sent: Tuesday, June 02, 2015 3:44 PM
To: [log in to unmask]
Subject: Re: [CODE4LIB] XSLT Advice
You really just need to wrap the label in the xsl:text and the xsl:value of in an xsl:if that tests whether the value-of XPath returns a string.
<dc:identifier><xsl:value-of
select="doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='name']/doc:element/doc:field[@name='value']"/>
<xsl:if
test="string(doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='volume']/doc:element/doc:field[@name='value'])">
<xsl:text> Vol. </xsl:text><xsl:value-of select="doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='volume']/doc:element/doc:field[@name='value']"/>
</xsl:if>
<xsl:if
test="string(doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='issue']/doc:element/doc:field[@name='value'])">
<xsl:text> Issue </xsl:text><xsl:value-of select="doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='issue']/doc:element/doc:field[@name='value']"/>
</xsl:if>
</dc:identifier>
If there's no name at all, you'd want to wrap an xsl:if around the dc:identifier so that you suppress an empty dc:identifier element.
On Tue, Jun 2, 2015 at 3:34 PM, Matt Sherman <[log in to unmask]>
wrote:
> Cool. I talked to Ron via phone so I am getting a better picture, but
> I am still happy to take more insights.
>
> So the larger context. I inherited a DSpace instance with three
> custom metadata fields which actually have some useful publication
> information, though they improperly titled them in by associating them
> with a dc prefix but there were two many to fix quickly and they
> haven't broken DSpace yet so we continue. So I added to the XSL to
> pull the data within the the custom fields to display "publication
> name" Vol. "publication volume" Issue "publication issue". That
> worked really well until I realized that there was no conditional so
> even when the fields are empty I still get: <dc:identifier>Vol.
> Issue</dc:identifier>
>
> So here are the Custom Metadata fields:
>
> dc.publication.issue
> dc.publication.name
> dc.publication.volume
>
>
> Here is the customized XSLT, with dc.identifier added for context of
> what the rest of the sheet looks like.
>
> <!-- dc.identifier -->
> <xsl:for-each
>
> select="doc:metadata/doc:element[@name='dc']/doc:element[@name='identifier']/doc:element/doc:field[@name='value']">
> <dc:identifier><xsl:value-of select="." /></dc:identifier>
> </xsl:for-each>
>
> <!-- dc.identifier.* -->
> <xsl:for-each
> select="doc:metadata/doc:element[@name='dc']/doc:element[@name='identifier']/doc:element/doc:element/doc:field[@name='value']">
> <dc:identifier><xsl:value-of select="."
> /></dc:identifier> </xsl:for-each>
>
> <!-- dc.publication fields to dc.identifier -->
> <dc:identifier><xsl:value-of
>
> select="doc:metadata/doc:element[@name='dc']/doc:element[@name='public
> ation']/doc:element[@name='name']/doc:element/doc:field[@name='value']
> "/><xsl:text>
> Vol. </xsl:text><xsl:value-of
>
> select="doc:metadata/doc:element[@name='dc']/doc:element[@name='public
> ation']/doc:element[@name='volume']/doc:element/doc:field[@name='value
> ']"/><xsl:text>
> Issue </xsl:text><xsl:value-of
>
> select="doc:metadata/doc:element[@name='dc']/doc:element[@name='public
> ation']/doc:element[@name='issue']/doc:element/doc:field[@name='value'
> ]"/></dc:identifier>
>
>
> Ron suggested that using choose and when and that does seem to make
> the most sense. The other trickiness is that I have found that some
> of these fields as filled when others are blank, such as their being a
> volume but not an issue. So I need to figure out how to test multiple
> fields so that I can have it display differently dependent on what has
> data or not at all none of the fields are filled, which is the case in
> items such as posters.
>
> So any thoughts would help. Thanks.
>
> On Tue, Jun 2, 2015 at 2:50 PM, Wick, Ryan <[log in to unmask]>
> wrote:
> > I agree with Stuart, post the example here.
> >
> > Or if you want more real-time chat there's always #code4lib IRC.
> >
> > For an XSLT resource, Dave Pawson's site is great:
> http://www.dpawson.co.uk/xsl/sect2/sect21.html
> >
> > Ryan Wick
> >
> > -----Original Message-----
> > From: Code for Libraries [mailto:[log in to unmask]] On Behalf
> > Of
> Stuart A. Yeates
> > Sent: Tuesday, June 02, 2015 11:46 AM
> > To: [log in to unmask]
> > Subject: Re: [CODE4LIB] XSLT Advice
> >
> > There are a number of experienced xslt'ers here. Post your example
> > to
> the group so we can all learn.
> >
> > Cheers
> > Stuart
> >
> > On Wednesday, June 3, 2015, Matt Sherman <[log in to unmask]>
> wrote:
> >
> >> Hi all,
> >>
> >> I am making a few corrections on an oai_dc.xslt file for our DSpace
> >> instance I slightly botched modifying to integrate some custom
> >> metadata into a dc.identifier citation in the OAI-PMH harvest. I
> >> need to get proper conditionals so it can display and harvest the
> >> metadata correctly and not run when there is no data in those
> >> fields. I have a pretty good idea what I need to do, and if this
> >> were like JavaScript or Python I could probably muddle through.
> >> The trouble is that I don't know the conditional syntax for XSLT
> >> quite well enough to know what I can do and thus need to do. Plus
> >> the online resources for learning/referencing XSLT for this are a
> >> bit shallow for what I need hence asking the group. So if there is
> >> anyone who knows XSLT really well that would be willing to talk
> >> with me for a bit to help me work through what I need to get the
> >> syntax to work like I want I would appreciate it. Thanks.
> >>
> >> Matt Sherman
> >>
> >
> >
> > --
> > --
> > ...let us be heard from red core to black sky
>
|