0

I have several entries like this:

<place label="Juan Fernandez"><placeName>Juan Fernandez</placeName><location><geo>-33.666667, -78.833333</geo></location></place>

and I want to transform it into

   <span label="Juan Fernandez" data-boo-coordinates ="-33.666667, -78.833333"> Juan Fernandez <location><geo>-33.666667, -78.833333</geo></location></span>

for the label, there is no fuss:

<xsl:template match="tei:place">
  <xsl:element name="span">
  <xsl:attribute name="label">
    <xsl:text>{@label}</xsl:text>
  </xsl:attribute>

I figured that something similar should work and tried several things, which I will list below: quite naturally the following does not work:

  <xsl:attribute name="data-boo-coordinates">
    <xsl:value-of select="geo"/>
  </xsl:attribute>

However, I thought this one should work:

  <xsl:attribute name="data-boo-coordinates">
    <xsl:value-of select="place/location/geo"/>
  </xsl:attribute>

the complete template for the place-elements

<xsl:template match="tei:place">
  <xsl:element name="span">
  <xsl:attribute name="label">
    <xsl:text>{@label}</xsl:text>
  </xsl:attribute>
  <xsl:attribute name="data-boo-coordinates">
    <xsl:value-of select="*/location/geo"/>
  </xsl:attribute>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

As you can see, I changed a bit again, hoping that it would get the node's text by using <xsl:value-of>. Am I doing sth. totally stupid here?

all the best and thank you for your time, K

2 Answers2

0

When I use the following for select it actually works:

  <xsl:attribute name="data-boo-coordinates">
    <xsl:value-of select="child::location/geo"/>
  </xsl:attribute>

context matters, I guess :-/

Can anyone maybe hint for a more elegant answer?

0

Why can't you use a literal result element and attribute value templates

<xsl:template match="tei:place">
  <span label="{@label}" data-boo-coordinates="{location/geo}">
    <xsl:apply-templates/>
  </span>
</xsl:template>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • tbh, I have no idea why I did not try that! Probably I was in to deep... ... :-D I need to cut down the verbosity of my script anyways. I actually prefer your answer over mine. So I'll upvote yours as answer and mark it as answered –  Jul 14 '20 at 12:07