Print

Print


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='publication']/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='publication']/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='publication']/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
>