从XML进行XSLT转换(XSLT translation from XML)

编程入门 行业动态 更新时间:2024-10-21 11:26:57
XML进行XSLT转换(XSLT translation from XML)

我想进行XSLT转换以使用条件查找某个值。

我的XML文件片段如下:

<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="sample.xslt"?> <ValuesList> <Values ID="ZLOV1FD23146" ParentID="ZLOV1GR00001" AllowUserValueAddition="true" UseValueID="false"> <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> <Language DimensionID="Language"/> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ABC</Value> <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">DEF</Value> </ValueGroup> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ASD</Value> <Value QualifierID="std.lang.all">qwer</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">FGH</Value> <Value QualifierID="lang_ZPIM1ID">dfghy</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">RST</Value> </ValueGroup> </Values> <Values ID="ZLOV1FDsdasda" ParentID="ZLOV1GR00002" AllowUserValueAddition="true" UseValueID="false"> <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> <Language DimensionID="Language"/> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ABC</Value> <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">asdas</Value> </ValueGroup> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ASD</Value> <Value QualifierID="std.lang.all">qwer</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">FGH</Value> <Value QualifierID="lang_ZPIM1ID">dfghy</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">iyi</Value> </ValueGroup> </Values> </ValuesList>

我需要创建sample.XSLT文件以满足以下条件:

识别只有一个“值”的“ValueGroup”元素,并检查该值是否在上下文“std.lang.all”中。 检查语言维度='语言' 输出应该在值ID |中 价值格式。 (例如,ZLOV1FD23146 | DEF)

我已经创建了XSLT文件,如下面的代码段,但不起作用:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="ValuesList/Values/ValueGroup"> <xsl:text> ID | Value</xsl:text> <xsl:text>&#x0A;</xsl:text> <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'"> <xsl:value-of select="concat(//Values/@ID,' |',Value,'&#x0A;')"></xsl:value-of> </xsl:if> </xsl:template> </xsl:stylesheet>

请帮助我......谢谢。

I would like to do a XSLT translation to find a certain value using a condition.

My XML files snippet as below:

<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="sample.xslt"?> <ValuesList> <Values ID="ZLOV1FD23146" ParentID="ZLOV1GR00001" AllowUserValueAddition="true" UseValueID="false"> <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> <Language DimensionID="Language"/> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ABC</Value> <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">DEF</Value> </ValueGroup> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ASD</Value> <Value QualifierID="std.lang.all">qwer</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">FGH</Value> <Value QualifierID="lang_ZPIM1ID">dfghy</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">RST</Value> </ValueGroup> </Values> <Values ID="ZLOV1FDsdasda" ParentID="ZLOV1GR00002" AllowUserValueAddition="true" UseValueID="false"> <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> <Language DimensionID="Language"/> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ABC</Value> <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">asdas</Value> </ValueGroup> <ValueGroup> <Value QualifierID="lang_ZPIM1ID">ASD</Value> <Value QualifierID="std.lang.all">qwer</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">FGH</Value> <Value QualifierID="lang_ZPIM1ID">dfghy</Value> </ValueGroup> <ValueGroup> <Value QualifierID="std.lang.all">iyi</Value> </ValueGroup> </Values> </ValuesList>

I need to create sample.XSLT file in order to meet below conditions:

Identify “ValueGroup” Elements which do have only one “Value” and check whether this value is in context “std.lang.all” . Check the Language Dimension='Language' The output should be in Values ID | Value format. (e.g, ZLOV1FD23146 | DEF)

I have created the XSLT file as below snippet but does not work:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="ValuesList/Values/ValueGroup"> <xsl:text> ID | Value</xsl:text> <xsl:text>&#x0A;</xsl:text> <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'"> <xsl:value-of select="concat(//Values/@ID,' |',Value,'&#x0A;')"></xsl:value-of> </xsl:if> </xsl:template> </xsl:stylesheet>

Kindly help me out..Thanks in advance.

最满意答案

你可以有这样的东西:

EDITED

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:text> ID | Value</xsl:text> <xsl:text>&#x0A;</xsl:text> <!-- Choose the nodes you want to output here. you can directly place the conditions in an attribute --> <xsl:apply-templates select="ValuesList/Values[Language[@DimensionID='Language']]"/> </xsl:template> <xsl:template match="Values"> <xsl:apply-templates select="ValueGroup[count(Value)=1 and Value/@QualifierID='std.lang.all']"/> </xsl:template> <xsl:template match="ValueGroup"> <xsl:value-of select="concat(ancestor::Values/@ID,' |',Value,'&#x0A;')"/> </xsl:template> </xsl:stylesheet>

you can have something like this:

EDITED

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:text> ID | Value</xsl:text> <xsl:text>&#x0A;</xsl:text> <!-- Choose the nodes you want to output here. you can directly place the conditions in an attribute --> <xsl:apply-templates select="ValuesList/Values[Language[@DimensionID='Language']]"/> </xsl:template> <xsl:template match="Values"> <xsl:apply-templates select="ValueGroup[count(Value)=1 and Value/@QualifierID='std.lang.all']"/> </xsl:template> <xsl:template match="ValueGroup"> <xsl:value-of select="concat(ancestor::Values/@ID,' |',Value,'&#x0A;')"/> </xsl:template> </xsl:stylesheet>

更多推荐

本文发布于:2023-08-07 00:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XML   XSLT   translation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!