- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试生成一个与初始文件几乎相同的 xml 文件,但我需要我的 xsl 工作表将其转换为仅包含
我的初始 xml 表如下:
<rentalProperties>
<property available="yes" contact="0423020892">
<type>house</type>
<price>800</price>
<address>
<streetNo>116</streetNo>
<street>Warrigal Road</street>
<suburb>Camberwell</suburb>
<state>VIC</state>
<zipcode>3124</zipcode>
</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
</rentalproperties>
我的 xsl:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="RentalProperties">
<xsl:apply-templates select="rentalProperties/property"/>
</xsl:element>
</xsl:template>
<xsl:template match="rentalProperties/property/type">
<xsl:element name="type" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="rentalProperties/property/price">
<xsl:element name="price" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="rentalProperties/property/address">
<xsl:element name="address" >
<xsl:value-of select="streetNo"/><xsl:value-of select="street"/><xsl:value-of select="suburb"/><xsl:value-of select="state"/><xsl:value-of select="zipcode"/>
</xsl:element>
</xsl:template>
<xsl:template match="rentalProperties/property/numberOfBedrooms">
<xsl:element name="numberOfBedrooms" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="rentalProperties/property/description">
<xsl:element name="description" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
输出会是这样的:
<RentalProperties>
<property>
<type>apartment</type>
<price>400</price>
<address>4/3,Acheron Avenue,Camberwell,VIC,3124, Australia</address>
<numberOfBedrooms>2</numberOfBedrooms>
<description>This two bedroom apartment is located in quiet tree lined street, just minutes from tram and easy walk to Camberwell Junction and train. Positioned on the 1st floor with sunny north facing lounge and balcony.
</description>
</property>
</RentalProperties>
谢谢
最佳答案
这可能是最简单的解决方案之一(根本没有显式条件,所有输出仅由标识模板生成):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"property
[not(contains('|unit|apartment|',
concat('|',type,'|')
)
)
or
not(numberOfBedrooms > 1)
]
"/>
</xsl:stylesheet>
应用于此 XML 文档时(提供的文档 -- 更正和放大):
<rentalProperties>
<property available="yes" contact="0423020892">
<type>house</type>
<price>800</price>
<address>
<streetNo>116</streetNo>
<street>Warrigal Road</street>
<suburb>Camberwell</suburb>
<state>VIC</state>
<zipcode>3124</zipcode>
</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="0423020899">
<type>apartment</type>
<price>500</price>
<address>
<streetNo>116</streetNo>
<street>Water St.</street>
<suburb>Hornsby</suburb>
<state>NSW</state>
<zipcode>2012</zipcode>
</address>
<numberOfBedrooms>2</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="0423011111">
<type>unit</type>
<price>800</price>
<address>
<streetNo>7</streetNo>
<street>Ryan St</street>
<suburb>Isacs</suburb>
<state>ACT</state>
<zipcode>2603</zipcode>
</address>
<numberOfBedrooms>1</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="04231234567">
<type>hotel</type>
<price>1200</price>
<address>
<streetNo>4</streetNo>
<street>Bench St.</street>
<suburb>Deakin</suburb>
<state>ACT</state>
<zipcode>2600</zipcode>
</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
</rentalProperties>
产生想要的、正确的结果(仅输出满足所有约束的属性之一):
<rentalProperties>
<property available="yes" contact="0423020899">
<type>apartment</type>
<price>500</price>
<address>
<streetNo>116</streetNo>
<street>Water St.</street>
<suburb>Hornsby</suburb>
<state>NSW</state>
<zipcode>2012</zipcode>
</address>
<numberOfBedrooms>2</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
</rentalProperties>
说明:用匹配任何不需要的属性的空模板覆盖 identity rule 。
关于XML 到 XML,XSLT 根据值省略特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7863660/
这是我在这里的第一篇文章,也是我第一次使用 C++。我正在查看从 Internet 获得的一些代码,但我对此有疑问。 它有一个 for 循环,像这样: for(cin >> t;t--;) 我明白它在
我目前正在开发一个网站,除其他外,该网站允许用户通过显示或隐藏他们已购买的商品来过滤市场。这适用于基本的 AJAX 调用,该调用传递可用过滤器的当前条件,然后使用 CodeIgniter 的事件记录构
我创建了一个 MWE,其中通过添加 来更改单行解决编译器错误。 以下代码无法编译: import java.util.List; public class MainClass { publi
当我想测试一些 PostgreSQL 函数 FOO() 的行为时,我发现执行类似 SELECT FOO(bar) 的查询很有用,bar一些数据我用作直接输入,而无需从真实表中SELECT。 我读到我们
在 PHP、Java、C++(以及许多其他语言)中,for 循环是这样使用的: for(int i=0;i<10;i++) 如果我已经初始化了i,我该如何省略初始化语句呢? 最佳答案 在 Java、C
我发现我们的 Android 应用出现了一个奇怪的问题,特别是在 4.4 版的 Moto X 上。 在偏好 Activity 中,所有标题的前 8 个字符都在开头用省略号截断。这也发生在溢出菜单和整个
我有一个 XElement,我必须解析它以删除结束标记中的空白。我的代码如下所示: var stringBuilder = new StringBuilder(); using (var string
假设我有两个接口(interface),X和 Y ,它们共享一些字段,但也有独立的字段: interface X { abc: number; foo: number; bar: numb
我有这个模型: var accountSchema = new mongoose.Schema({ 'seeker': { 'fullName': String,
我在 R 中运行一个具有大量时间和位置固定效应的回归。我尝试将一个漂亮的汇总表输出到 Latex 中。我从 stargazer 包切换到 huxtable,因为 stargazer 在忽略固定效果时表
假设我有一个数据框: a df a b c d 1 0 9 10 2 1 10 13 3 NA 11 14 4 3 NA 7 5 4 13 22 现在假设我
我在 R 中运行一个具有大量时间和位置固定效应的回归。我尝试将一个漂亮的汇总表输出到 Latex 中。我从 stargazer 包切换到 huxtable,因为 stargazer 在忽略固定效果时表
我想删除一个属性并返回一个新对象而不改变原始对象。 我知道我们可以像这样使用 Lodash 轻松做到这一点: const profile = { name: 'Maria', age: 30 } _.
我正在通过更改一些内容来修改 javascript 对象。当我重新创建它时,我会得到每个 key 对的索引号。 "0":{...},"1":{...}, 如何删除/省略这些 0、1、2、3、4 数字的
我正在一个非常方便且名称丰富的网站 here 上完成示例之一。 ,具体来说: func applyMutliplication(value: Int, multFunction: Int -> Int
这个问题在这里已经有了答案: Why do java source files require package declarations? (4 个答案) 关闭 6 年前。 我是 Java 的新手,
在下面的代码中: Widget makeWidget() { return Widget(); } void foo(Widget widget) { ... } foo(makeWid
这是我使用下面的调用调用的过程: CALL abc('01-04-2011','14-04-2014','28,29,36,37,38','33,34,35,41,42,43') 但问题是下面提到的查
嘿,我正在寻找一种在 yui 数据表中省略文本的好方法。我的意思是,格式化文本,使其很好地适合其单元格,并且如果文本必须被 chop ,则在其后面有一个椭圆 (...)。 我想在不使用 CSS 选择器
我有一个如下表(记录)。 ID Status AA124 Pass AA125 Pass Z_AA134 Fail Z_AA135
我是一名优秀的程序员,十分优秀!