0
を使用してJSON出力のいくつかの要素を削除する必要があるとの交換をした:<p>XSLT</p>を使用して私の入力有効なXMLファイルであるXML入力からJSONの出力でいくつかの要素を私はいくつかの要素を削除するXSLT
:私は、出力JSONを取得<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:template match="items">
items: [
<xsl:apply-templates/>
]
</xsl:template>
<xsl:template match="item">
{
<xsl:apply-templates/>
},
</xsl:template>
<xsl:template match="statement">
"statement": "<xsl:apply-templates/>"
</xsl:template>
<xsl:template match="response">
"response": "<xsl:apply-templates/>"
</xsl:template>
<xsl:template match="media">
media: {
<xsl:apply-templates/>
}
</xsl:template>
<xsl:template match="type">
"type": "<xsl:apply-templates/>"
</xsl:template>
<xsl:template match="link">
<xsl:text>"link": "files/</xsl:text>
<xsl:value-of select="tokenize(., '/')[last()]"/>"
</xsl:template>
<xsl:template match="p">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
:私はとして使用
<items>
<item>
<statement/>
<response/>
<media>
<type>img</type>
<link>SLP.jpg</link>
</media>
</item>
<item>
<statement>walking time bomb.</statement>
<response>
<p>Developing additional problems with your health.</p>
</response>
<media>
<type>html</type>
<link>Brightcove.com%2FZ678766-1.avi</link>
</media>
</item>
</items>
XSL
しかし、私は以下のようなとして出力する必要があります。
media: {
"type": "img"
"link": "files/SLP.jpg"
}
items: [
{
"statement": "walking time bomb."
"response": "Developing additional problems with your health."
media: {
"type": "html"
"link": "files/Brightcove.com%2FZ678766-1.avi"
}
},
私は最初のメディアファイル(JPG形式)は上記などの出力に個別に来る必要があります。これで私を助けてください。事前
xsltと希望する出力に基づいて、xmlの2番目のitem要素は、最初の項目内のitems要素内にある必要があります。 –
空のノードを除外する場合は、セレクタを変更する必要があります。 –
はい@MatthewWhited。私はlistitem要素の外側にメディア要素を置くと入力XMLファイルが有効にならないので、最初のメディア要素自体がリスト項目の前に別々に来る必要があります。したがって、listitem要素内でのみ使用されます。しかし、私は上記のように予想される出力を必要とします – User501