Thanks for the help everyone, I've got it working great now. Below is the XSLT I ended up with and a few examples of the returns I get. All of the input was extremely helpful in figuring out the best solution. XSLT Change: <!-- dc.publication fields to dc.identifier --> <xsl:for-each select="doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']"> <dc:identifier><xsl:value-of select="doc:element[@name='name']/doc:element/doc:field[@name='value']"/> <xsl:if test="string(doc:element[@name='volume']/doc:element/doc:field[@name='value'])"> <xsl:text> Vol. </xsl:text> <xsl:value-of select="doc:element[@name='volume']/doc:element/doc:field[@name='value']"/> </xsl:if> <xsl:if test="string(doc:element[@name='issue']/doc:element/doc:field[@name='value'])"> <xsl:text> Issue </xsl:text> <xsl:value-of select="doc:element[@name='issue']/doc:element/doc:field[@name='value']"/> </xsl:if> </dc:identifier> </xsl:for-each> Output Examples: <dc:identifier>Advances in Computer Science and Engineering Vol. 1 Issue 1</dc:identifier> <dc:identifier>Journal of Intelligent and Robotic Systems Vol. 24</dc:identifier> <dc:identifier>Vol. 2</dc:identifier> On Wed, Jun 3, 2015 at 3:15 PM, Matt Sherman <[log in to unmask]> wrote: > Thanks for all the suggestions folks, other things at work have > prevented me from working on this quite yet but there is a lot of > helpful advice and suggestions here so thanks. As a note on the > <xsl:for-each> that is actually the default dc_oai.xsl file for DSpace > and not my own work so feel free to ding the folks over there for that > choice. This gives me a better feel for how XSLT hands conditionals > and some ideas on how to tackle it. Though I would be curious to ask > if there is a reason to default to <xsl:if> vs. <xsl:choose>? I'm not > sure that I necessarily need a switch to fix this problem but I want > to hear the thought process so I know how to better think over these > options in the future. > > On Tue, Jun 2, 2015 at 5:21 PM, Boheemen, Peter van > <[log in to unmask]> wrote: >> You should use a template that is only applied when the specified field is there. These templates in xslt are applied automatically only if the field is there: >> >> <xsl:template match="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:apply-templates/> >> </xsl:template> >> >> If the field is defined, but empty you should do: >> >> <xsl:template match="doc:metadata/doc:element[@name='dc']/doc:element[@name='publication']/doc:element[@name='volume']/doc:element/doc:field[@name='value']"> >> <xsl:if test="not(.='')"> >> <xsl:text>Vol. </xsl:text >> <xsl:apply-templates/> >> </xsl:if> >> </xsl:template> >> >> Xslt is not a procedural language, you should hardly ever use <xsl:for-each> >> >> Peter >> >> >> -----Original Message----- >> From: Code for Libraries [mailto:[log in to unmask]] On Behalf Of Matt Sherman >> Sent: dinsdag 2 juni 2015 21:35 >> To: [log in to unmask] >> Subject: Re: [CODE4LIB] XSLT Advice >> >> 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