0

I've the dictionary in inside the tag and I wanted to create the table from it. Here is the xml file I've

<parent>
  <thread thread_id="5e778ef9a28f9a51fec330b4">
    {'relative_to_thread_interactors': 1.0, 'relative_to_self_threads': 1.0}
  </thread>
  <thread thread_id="5e778ef9a28f2b51fec330A3">
    {'relative_to_thread_interactors': 2.0, 'relative_to_self_threads': 1.0}
  </thread> 
</parent>

And here is my xslt


<xsl:for-each select="parent/thread">
  <tr>
    <td><xsl:value-of select="@thread_id"/></td>
    <td><xsl:value-of select="thread"/></td>
  </tr>
</xsl:for-each>

Now my question is how to create a table from the dictionary value?

| thread_id                | relative_to_thread_interactors |
|--------------------------|--------------------------------|
| 5e778ef9a28f2b51fec330A3 | 2.0                            |

1
  • Please state which version of XSLT your processor supports. Commented Mar 25, 2020 at 19:02

1 Answer 1

2

In XSLT 1.0 you can do:

<xsl:template match="/parent">
    <table>
        <tr>
            <th>thread_id</th>
            <th>relative_to_thread_interactors</th>
        </tr>
        <xsl:for-each select="thread">
            <tr>
                <td>
                    <xsl:value-of select="@thread_id"/>
                </td>
                <td>
                    <xsl:value-of select='substring-before(substring-after(., "&apos;relative_to_thread_interactors&apos;: "), ",")'/>
                </td>
            </tr>
        </xsl:for-each>
    </table>
</xsl:template>

In XSLT 2.0 it could be more elegant by using regex.

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

2 Comments

Hey that works. Found this substring-before(haystack ,needle ) in mozilla doc 😂
Hi Michael. Is it possible to print all the keys in that dictionary. ?

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.