【发布时间】:2017-04-25 11:59:00
【问题描述】:
我有这样的 xml 文档:
<OrdersSchedulePDFView>
<OrdersSchedulePDFViewRow>
<Items>
<ItemDesc>Content1</ItemDesc>
<ItemDesc>Content2</ItemDesc>
</Items>
<Locations>
<LocName>Content3</LocName>
<LocName>Content4</LocName>
</Locations>
</OrdersSchedulePDFViewRow>
</OrdersSchedulePDFView>
请给我一个示例 xsl 文件,我可以在其中通过模板获取 ItemDesc 和 LocName 元素。提前致谢 这是我的 xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:template match="OrdersSchedulePDFView">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:for-each select="OrdersSchedulePDFViewRow">
<fo:page-sequence master-reference="all">
<fo:flow flow-name="xsl-region-body">
<xsl:template match="Locations">
<xsl:copy>
<xsl:apply-templates select="LocName"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Items">
<xsl:copy>
<xsl:apply-templates select="ItemDesc"/>
</xsl:copy>
</xsl:template>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
你到底想做什么?你可以试试
<xsl:template match="LocName">(如果我们可能看不到的元素上没有命名空间),但是模板应该做什么? -
我需要打印 ItemDesc 和 LocName 元素。但我无法通过
获得它们 -
为什么不发布您的尝试以便我们修复它,而不必从头开始为您编写代码。另外,显示您期望得到的准确输出。
-
然后最小化 - 请参阅:minimal reproducible example
-
@ВячеславКошман 你的 XSLT 不能工作,因为模板不能嵌套。我不能告诉你如何解决它,因为你还没有发布预期的输出。
标签: apache xslt apache-fop