如何用WP ALL IMPORT将XML属性组导入WooCommerce商品描述?
使用WP All Import for WooCommerce导入XML规格到商品描述的方法
需求说明
需要将XML中<attribute_group name="Specs">下的所有属性导入为WooCommerce商品描述的HTML内容,属性的数量、种类、顺序不固定,仅以该属性组标签为识别标准。
源XML示例
<attribute_group name="Specs"> <attribute name="color">White</attribute> <attribute name="series">Basic</attribute> <attribute name="power">40 W</attribute> <attribute name="voltage">220 V</attribute> <attribute name="SPL">90 dB</attribute> <attribute name="material">Wood</attribute> <attribute name="package">1 Pair</attribute> </attribute_group>
期望生成的商品描述HTML
<p>Specs</p> <p>color : White</p> <p>series : Basic</p> <p>power : 40 W</p> <p>voltage : 220 V</p> <p>SPL : 90 dB</p> <p>material : Wood</p> <p>package : 1 Pair</p>
实现步骤
- 进入WP All Import导入向导,选择目标XML数据源,完成基础导入配置后,进入自定义字段映射环节。
- 找到「商品描述(Product Description)」的映射输入框,点击输入框上方的**「循环」(Loop)**按钮,打开循环设置面板。
- 在循环的「XPath查询」输入框中,填入定位Specs属性组下所有attribute节点的表达式:
//attribute_group[@name='Specs']/attribute - 构建循环输出模板:
- 先在循环模板外添加标题行:
<p>Specs</p> - 在循环内容区域,填入每个属性的HTML格式:
其中<p>{@name} : {.}</p>{@name}会读取当前attribute节点的name属性值,{.}会读取节点内的文本内容。
- 先在循环模板外添加标题行:
- (可选)如果需要清理文本前后的多余空格,可以使用WP All Import的内置函数优化模板:
<p>{trim(@name)} : {trim(.)}</p> - 完成设置后,点击「预览」确认生成的商品描述格式符合预期,无误后执行正式导入。
注意事项
- WP All Import会自动遍历所有匹配的attribute节点,不管数量多少、顺序如何,都会按XML中的顺序生成对应内容,适配不同商品的属性差异。
- 如果XML中存在多个
attribute_group标签,该XPath表达式只会定位到name="Specs"的组,不会混淆其他属性组。
内容的提问来源于stack exchange,提问作者fou fou
相关产品推荐
相关产品推荐

