0

Sorry in advance if there has been an answer before like mine, but I have checked and haven't found exactly an answer this simple issue:

<self-uri xlink:href="http://www.harmreductionjournal.com/content/1/1/5">

All I want to do is to select the value of the attribute "xlink:href"

Applying the following selector always returns empty result:

<xsl:value-of select="@xlink:href"/>

I have iterated through the attribute values during processing

xlink:href: http://www.harmreductionjournal.com/content/1/1/5

My question is very simple: how can I get the value of an atribute that has a namespace? It was my understanding it should work like this.

If you can point me to the right question on SO that will also suffice.

Thanks in advance.

EDIT:

Based on the answers I have checked my root stylesheet declaration and it looks like this:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:mml="http://www.w3.org/1998/Math/MathML"
  exclude-result-prefixes="xlink mml">

I'm guessing the exclude attribute has something to do with the issue. If I replace it I find that it still doesn't work and the result xml is full with it on random places.

1
  • Show us minimal but complete samples of XSLT, XML input, wanted result and current result to allow us to reproduce the problem. So far we need to guess which namespaces the XML input uses and in which context you have the xsl:value-of. Commented Jul 8, 2013 at 10:50

2 Answers 2

2

Your approach should work, as long as your XSL file has the same prefix mapped to the same namespace. In other words, your XSL file should have the namespace mapping

xmlns:xlink="..."

where ... is the same value as defined in your source document for that namespace prefix.

Sign up to request clarification or add additional context in comments.

Comments

1
<xsl:template match="self-uri">
  <xsl:value-of
   select="@xlink:href"
   xmlns:xlink="http://www.w3.org/1999/xlink"/>
</xsl:template>

should do, assuming the input document uses http://www.w3.org/TR/xlink11/. Of course you would usually simply put the xmlns:xlink="http://www.w3.org/1999/xlink" on the xsl:stylesheet element of your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.