Xml XSL试图让JSON工作
正在尝试获取XMLXml XSL试图让JSON工作,xml,json,xslt,Xml,Json,Xslt,正在尝试获取XML <user-types> <section id="11" handle="user-types">User types</section> <entry id="9"> <name mode="unformatted" handle="home-owner" word-count="2" lang="en" handle-en="home-owner"><![CDATA[Hom
<user-types>
<section id="11" handle="user-types">User types</section>
<entry id="9">
<name mode="unformatted" handle="home-owner" word-count="2" lang="en" handle-en="home-owner"><![CDATA[Home owner]]></name>
</entry>
<entry id="7">
<name mode="unformatted" handle="contractor-residential" word-count="2" lang="en" handle-en="contractor-residential"><![CDATA[Contractor (residential)]]></name>
</entry>
<entry id="8">
<name mode="unformatted" handle="contractor-non-residential" word-count="2" lang="en" handle-en="contractor-non-residential"><![CDATA[Contractor (non-residential)]]></name>
</entry>
<entry id="10">
<name mode="unformatted" handle="commercial-property-owner" word-count="3" lang="en" handle-en="commercial-property-owner"><![CDATA[Commercial property owner]]></name>
</entry>
</user-types>
根据xml到json的文档,使用这个XSL似乎不是为了这样使用 使用此文档将生成一个数组:
<user-types>
<section id="11" handle="user-types">User types</section>
<entry>
<item id="9">
<name mode="unformatted" handle="home-owner" word-count="2" lang="en"
handle-en="home-owner"><![CDATA[Home owner]]></name>
</item>
<item id="7">
<name mode="unformatted" handle="contractor-residential" word-count="2" lang="en"
handle-en="contractor-residential"><![CDATA[Contractor (residential)]]></name>
</item>
<item id="8">
<name mode="unformatted" handle="contractor-non-residential" word-count="2" lang="en"
handle-en="contractor-non-residential"><![CDATA[Contractor (non-residential)]]></name>
</item>
<item id="10">
<name mode="unformatted" handle="commercial-property-owner" word-count="3" lang="en"
handle-en="commercial-property-owner"><![CDATA[Commercial property owner]]></name>
</item>
</entry>
</user-types>
结果看起来像是你想要的吗?可以这样修改XML吗?否则,恐怕您必须将xml更改为json才能处理您的xml结构。此处链接脚本的作者。
请参见您可以在我看不到任何计算机程序的地方测试结果。您能展示一下您正在试图优化的将XML转换为JSON的代码吗?使用这个XSL,我无法使用您指向实际输出的样式表重现您的结果,我看到的结果比您报告的要糟糕得多。我建议你寻找一个更好的源代码来复制你的代码。这是行不通的,因为这是我需要支持的众多示例之一。我不能像这样自动完成任务。这并不是否决这个答案的理由。那么,您是否能够使用自定义xslt而不是您链接的xslt?这似乎不是一个答案。我希望将xml修改为json,以满足将xml转换为json的需要
<user-types>
<section id="11" handle="user-types">User types</section>
<entry>
<item id="9">
<name mode="unformatted" handle="home-owner" word-count="2" lang="en"
handle-en="home-owner"><![CDATA[Home owner]]></name>
</item>
<item id="7">
<name mode="unformatted" handle="contractor-residential" word-count="2" lang="en"
handle-en="contractor-residential"><![CDATA[Contractor (residential)]]></name>
</item>
<item id="8">
<name mode="unformatted" handle="contractor-non-residential" word-count="2" lang="en"
handle-en="contractor-non-residential"><![CDATA[Contractor (non-residential)]]></name>
</item>
<item id="10">
<name mode="unformatted" handle="commercial-property-owner" word-count="3" lang="en"
handle-en="commercial-property-owner"><![CDATA[Commercial property owner]]></name>
</item>
</entry>
</user-types>