SQLServer から XML が出ています。ノードの名前を条件付きで変更できる SQLServer を取得できなかったので、後で XSLT を使用して変更します。XSLT で何をしているのかよくわかりません。StackOverFlow で検索して見つけたものからソリューションをまとめました。私が抱えている問題は、入力に子がない (したがってタグが 1 つしかない) タグが展開され、変換後に開始タグと終了タグを持つことです。帯域幅が問題になるユーザーが十分にいるので、これを防ぎたいと思います。
入力は次のとおりです。
<評価データ>
<コントロール>
<questRequiredOverride>N</questRequiredOverride>
</コントロール>
<パス>
<path id="SJ">
<questionFile timeScreen="" timeEstimate="0">SJ-CVS-Section-Mgt</questionFile>
<questionFile timeScreen="SitJudge" timeEstimate="5">SJ-CVS-Mgt</questionFile>
<questionFile timeScreen="SitJudge" timeEstimate="5">SJ-CVS-Mgt-SS</questionFile>
<シーケンス>
<グループ>
<content_block presentation="SituationalJudgmentInstructions"
type="指示">
<質問>
<question id="sjex"/>
</質問>
</content_block>
<content_block presentation="SituationalJudgmentQuestions" type="演習"
パス="1">
<質問>
<question id="sj6_Mgt"/>
<question id="sj7_Mgt"/>
</質問>
</content_block>
<content_block presentation="SituationalJudgmentQuestions" type="演習"
パス="2">
<質問>
<question id="sj13_SS"/>
<question id="sj12_SS"/>
<question id="sj10_SS"/>
<question id="sj8_SS"/>
<質問ID="sj5_SS"/>
<質問ID="sj3_SS"/>
</質問>
</content_block>
<content_block presentation="休憩" type="休憩"/>
</グループ>
</シーケンス>
</パス>
...
<path id="スコアリング">
<シーケンス>
<グループ>
<content_block presentation="Scoring" type="scoring"/>
</グループ>
</シーケンス>
</パス>
<path id="フィードバック">
<questionFile timeScreen="" timeEstimate="0">フィードバック-CVS</questionFile>
<シーケンス>
<グループ>
<content_block presentation="フィードバック" type="演習" path="1">
<質問>
<質問ID="fb30"/>
<質問ID="fb32"/>
<質問ID="fb40"/>
<質問ID="fb50"/>
</質問>
</content_block>
</グループ>
</シーケンス>
</パス>
</パス>
</評価データ>
XSLT は
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
バージョン="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="content_block">
<xsl:要素名="{@type}">
<xsl:apply-templates select="@*|node()"></xsl:apply-templates>
</xsl:要素>
</xsl:テンプレート>
<xsl:template match="@*|node()">
<xsl:コピー>
<xsl:apply-templates select="@*|node()"/>
</xsl:コピー>
</xsl:テンプレート>
</xsl:スタイルシート>
...出力は次のとおりです。
<評価データ>
<コントロール>
<questRequiredOverride>N</questRequiredOverride>
</コントロール>
<パス>
<path id="SJ">
<questionFile timeScreen="" timeEstimate="0">SJ-CVS-Section-Mgt</questionFile>
<questionFile timeScreen="SitJudge" timeEstimate="5">SJ-CVS-Mgt</questionFile>
<questionFile timeScreen="SitJudge" timeEstimate="5">SJ-CVS-Mgt-SS</questionFile>
<シーケンス>
<グループ>
<instructions presentation="SituationalJudgmentInstructions" type="instructions">
<質問>
<question id="sjex"> </question>
</質問>
</指示>
<exercise presentation="SituationalJudgmentQuestions" type="exercise" path="1">
<質問>
<question id="sj6_Mgt"> </question>
<question id="sj7_Mgt"> </question>
</質問>
</演習>
<exercise presentation="SituationalJudgmentQuestions" type="exercise" path="2">
<質問>
<question id="sj13_SS"> </question>
<question id="sj12_SS"> </question>
<question id="sj10_SS"> </question>
<question id="sj8_SS"> </question>
<question id="sj5_SS"> </question>
<question id="sj3_SS"> </question>
</質問>
</演習>
<休憩プレゼンテーション="休憩" type="休憩"> </休憩>
</グループ>
</シーケンス>
</パス>
...
<path id="スコアリング">
<シーケンス>
<グループ>
<scoring presentation="Scoring" type="scoring"> </scoring>
</グループ>
</シーケンス>
</パス>
<path id="フィードバック">
<questionFile timeScreen="" timeEstimate="0">フィードバック-CVS</questionFile>
<シーケンス>
<グループ>
<エクササイズ プレゼンテーション="フィードバック" タイプ="エクササイズ" パス="1">
<質問>
<question id="fb30"> </question>
<question id="fb32"> </question>
<question id="fb40"> </question>
<question id="fb50"> </question>
</質問>
</演習>
</グループ>
</シーケンス>
</パス>
</パス>
</評価データ>
各質問タグが「分解」されていることに注意してください。実際の XML には、ここで示したよりもはるかに多くのものがあります。
この質問をまとめているときに気づいたことの 1 つは、変換によって、変換された XML にも UTF-16 エンコーディングが追加されていることです。誰かがそれを修正する方法について何か考えがあれば、それも大歓迎です:)。
更新
XML と XSL の両方を ASP Classic の MSXML2.DOMDocument.3.0 にロードし、transformNode を使用しています。結果の文字列に対して Replace を使用して UTF エンコーディングを修正できましたが、この解決策には満足していません。