如何通过XSL在XML文件中添加分层标记?

时间:2010-04-15 10:40:37

标签: xml

我在XML转换中遇到了问题。 XML标记层次结构如下:

<Pick_Slips_Detail_Lines_S3>
<Header_Custom_Section_S15>
//This tag contains the header data (Example:Pick Slip Number)
</Header_Custom_Section_S15>
Then the Detail lines are printed.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>

My requirement is to:
<PickSlipList>
<Pick_Slips_Detail_Lines_S3>
<Header_Custom_Section_S15>
//This tag contains the header data (Example:Pick Slip Number)
</Header_Custom_Section_S15>
Then the Detail lines are printed.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>
</PickSlipList>

我的要求是在标题的每个页面上打印Pick Slip Number。由于<Pick_Slips_Detail_Lines_S3><Header_Custom_Section_S15>没有父标记,因此我在打印时遇到问题。

我正在尝试在XML转换中搜索某些内容。但我不知道如何转换XML标记层次结构。

2 个答案:

答案 0 :(得分:0)

这是:

<Pick_Slips_Detail_Lines_S3>
<Header_Custom_Section_S15>
//This tag contains the header data (Example:Pick Slip Number)
</Header_Custom_Section_S15>
Then the Detail lines are printed.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>

<Pick_Slips_Detail_Lines_S3>
The detail lines are printed. This detail line belongs to the previous Pick Slip Number.
</Pick_Slips_Detail_Lines_S3>

您的所有XML输入?这不是格式良好的XML;我不认为你会得到一个XSL引擎把它作为输入。在对数据进行任何转换之前,您可能需要预先处理数据。更好的是,修改开始创建错误XML的系统部分。

答案 1 :(得分:-1)