入力XMLファイルをJSON出力に変換している間に、一重引用符の属性は二重引用符に変換されます。XSLTを使用してJSON出力の一重引用符変換(XMLからJSON)を作成する
上記の問題を解決するには誰もガイドしてください。
私の入力XMLファイルには、次のとおりです。私が使用している
<items>
<mlu1_item>
<title>
<strong>Creatinine</strong>
</title>
<content>
<p>Creatinine is a normal waste product</p>
<ul>
<li>males</li>
<li>females</li>
</ul>
<p>If your creatinine level kidneys.</p>
</content>
<mlu1_button/>
<button_class/>
<link/>
<image>icon.png</image>
</mlu1_item>
</items>
XSL:
items:
[
{
"title": "Creatinine"
"content": "<h4>Creatinine</h4>
**<div class="text-left">**
<p>Creatinine is a normal waste product</p>
<ul>
<li>males</li>
<li>females</li>
</ul>
<p>If your creatinine level kidneys.</p>
</div>",
"link": "",
"image": "img/icon.png",
"top": "5%",
"left": "52%",
"size": "",
"color": "",
"borderColor": "#00",
"bgInfoColor": "#fff",
"borderWidth": "0px",
},
]
};
しかし、私のように出力を期待:私はようだ
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:json="http://json.org/" exclude-result-prefixes="#all">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" />
<xsl:template match="my-node">
<xsl:value-of select="json:generate(.)"/>
</xsl:template>
<xsl:template match="items">
items:
[
<xsl:for-each select="mlu1_item">
{
"title": "<xsl:value-of select="title/strong"/>"
"content": "<h4><xsl:value-of select="title/strong"/></h4>**<div class='text-left'>**<xsl:apply-templates select="content"/></div>",
"link": "",
"image": "img/<xsl:value-of select="image"/>",
"top": "5%",
"left": "52%",
"size": "",
"color": "",
"borderColor": "#00",
"bgInfoColor": "#fff",
"borderWidth": "0px",
},
</xsl:for-each>
]
</xsl:template>
<xsl:template match="p">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="ol">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="ul">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="li">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="content">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
出力JSON:
items:
[
{
"title": "Creatinine"
"content": "<h4>Creatinine</h4>
**<div class='text-left'>**
<p>Creatinine is a normal waste product</p>
<ul>
<li>males</li>
<li>females</li>
</ul>
<p>If your creatinine level kidneys.</p>
</div>",
"link": "",
"image": "img/icon.png",
"top": "5%",
"left": "52%",
"size": "",
"color": "",
"borderColor": "#00",
"bgInfoColor": "#fff",
"borderWidth": "0px",
},
]
};
JSON出力のdiv属性宣言の一重引用符を残したい
どのXSLTプロセッサを使用しますか?最近のSaxonやAltovaのリリースでは、XMLをシリアル化してJSONを作成するXPath関数がサポートされているため、適切なフォーマットやバランスの取れた引用符やエスケープされた引用符を作成するためのテンプレートよりも優れています。 –
Saxon-PE 9.6.0.7バージョン変換に使用しました –
oXygenの中でSaxonを使用していますか?出力については、json.orgで指定されているようなJSONになっていますか? –