0

I've been trying to loop attributes of a XML that have namespace, after sometime I was able to get elements using namespace, but now I'm getting a hard time to loop through attributes.

All examples I've found works without namespace on it.

This is what I have so far:

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="TransactionDataOfRequest">
  <xsl:output method="text" indent="no"/>
  <xsl:output omit-xml-declaration="yes" encoding="UTF-8"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">

    <xsl:for-each select="//x:form">
      <xsl:value-of select="//x:name"/>
    </xsl:for-each>

  </xsl:template>

  <xsl:template match="/">

    <xsl:copy-of select="//x:request"/>
    <xsl:text>&#10;</xsl:text>
    <!-- newline character -->
    <xsl:value-of select="//x:qform"/>
  </xsl:template>
</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<transaction xmlns="TransactionDataOfRequest" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <success>true</success>
  <code>0</code>
  <value>
    <request>INC000158</request>
</descript>
    <qform>Save</qform>
    <form>
      <add name="ADM_1" title="B" type="String" isList="false">Americana</add>
      <add name="ADM_2" title="Question?" type="String" isList="false">No</add>
      <add name="ADM_3" title="State" type="String" isList="false">ss</add>
    </form>
  </value>
</transaction>

1 Answer 1

1

A default namespace declaration like xmlns="TransactionDataOfRequest" only applies to element nodes, not to attribute nodes. So you would select an attribute simply as e.g. //x:form/x:add/@title.

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

1 Comment

Thanks Martin! I was getting a hard time to find where I was wrong.

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.