Reputation: 171
I would like to enter into an xml file some elements retrieved from an api request, using xslt 2.0.
for example I have this query: https://api.zotero.org/users/2138134/items?tag=quaderni&format=tei
which returns
<listBibl xmlns="http://www.tei-c.org/ns/1.0">
<biblStruct type="journalArticle" xml:id="zoteroItem_1">
<analytic>
<title level="a"/>
</analytic>
<monogr>
<title level="j">Quaderni di Archeologia della Libia</title>
<edition>31</edition>
<imprint>
<biblScope type="vol">vol. I</biblScope>
<date>1950</date>
</imprint>
</monogr>
</biblStruct>
</listBibl>
I would then like to add some of the content I have there to my file. let's say I have
<bibliography><ptr target="quaderni"></bibliography>
and I want to have
<bibliography>
<listBibl xmlns="http://www.tei-c.org/ns/1.0">
<biblStruct type="journalArticle" xml:id="zoteroItem_1">
<analytic>
<title level="a"/>
</analytic>
<monogr>
<title level="j">Quaderni di Archeologia della Libia</title>
<edition>31</edition>
<imprint>
<biblScope type="vol">vol. I</biblScope>
<date>1950</date>
</imprint>
</monogr>
</biblStruct>
</listBibl>
</bibliography>
I have put into a variable the api query based on the content of the @target and I thought I would then be able to simply use the fn:document to parse the xml, but it does not seem to work, and I fear this is just not possible. thanks in advance for any help.
Upvotes: 0
Views: 356
Reputation: 167561
Here is an example doing what you say you tried:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:param name="url1" select="'https://api.zotero.org/users/2138134/items?tag=quaderni&format=tei'"/>
<xsl:output indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ptr[@target = 'quaderni']">
<xsl:copy-of select="doc($url1)"/>
</xsl:template>
</xsl:stylesheet>
Output for me is
<bibliography>
<listBibl xmlns="http://www.tei-c.org/ns/1.0">
<biblStruct type="journalArticle" xml:id="zoteroItem_1">
<analytic>
<title level="a"/>
</analytic>
<monogr>
<title level="j">Quaderni di Archeologia della Libia</title>
<edition>31</edition>
<imprint>
<biblScope type="vol">vol. I</biblScope>
<date>1950</date>
</imprint>
</monogr>
</biblStruct>
</listBibl>
</bibliography>
Upvotes: 1