<name>
<pattern>/Book/Title</pattern>
<pattern>/Newspaper/Title</pattern>
</name>
<Description>
<pattern>/Book/Descriptions/*</pattern>
<pattern>/Newspaper/Descriptions/*<pattern>
</Description>
I have a collection of different XML files. Given a XML file like above, I'd like to extract semantically similar information from all of them and display it in a JSON format. E.g. I might want to extract name and description from one of the XMLs encoding book information to receive a file like:
"name": "Harry Potter",
"description": ["DescA", "DescB"]
The XML file belonging to that might look like:
<Book>
<Title>Harry Potter</Title>
<Author>J.K. Rowling </Author>
<Description lang="de">DescA</Description>
<Description lang="en">DescB</Description>
</Book>
I thought about using XSL 3.0 to use the xsl:evaluate
function, but it is not working the way I expected.
With a code snippet like:
<xsl:variable name="pattern">
<xsl:evaluate xpath="/Book/Descriptions/*" context-item="$root"/>
</xsl:variable>
<xsl:for-each select="$pattern">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
I only get all Descriptions as one long concatenated string, instead of being able to loop through them. I would have expected an output like "DescA,DescB,", but only get "DescADescB,". I'm quite unfamiliar with XSL, so any help is appreciated. Be it in how to design the above described mapping in a more efficient way or how to use the evaluate function in such a way, that I can get the individual Descriptions. For information, currently using Saxon XSL HE 10.5 with Java.
as="item()*"
on yourxsl:variable
, if you need a variable withxsl:evaluate
. And for the whole question, a minimal but complete sample to reproduce things would help. – Martin Honnen