从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>
</xsl:text> <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'"> <xsl:value-of select="concat(//Values/@ID,' |',Value,'
')"></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>
</xsl:text> <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'"> <xsl:value-of select="concat(//Values/@ID,' |',Value,'
')"></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>
</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,'
')"/> </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>
</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,'
')"/> </xsl:template> </xsl:stylesheet>更多推荐
发布评论