XSL 1.0在每个循环中选择具有true/false值

发布于 2025-02-05 12:09:46 字数 9450 浏览 1 评论 0原文

输入XML:

        <?xml version="1.0" encoding="UTF-8"?><MetrixXML xmlns="http://www.lithotechnics.com" DocumentVersion="Metrix" SchemaVersion="1.0" Units="Millimeters">
          <ResourcePool>
            <RGBColor Blue="167" Green="201" ID="Ref_1" Red="108"/>
            <Stock Grade="1" ID="Ref_3" Name="" Thickness="0.25" Vendor="" Weight="135" WeightUnit="gsm"/>
            <FoldingScheme ID="Ref_4" JDFFoldCatalog="F8-7"/>
            <Ink ID="Ref_5" Name="Cyan" Type="ProcessCyan">
              <CMYKColorRef rRef="Ref_6"/>
            </Ink>
            <CMYKColor Black="0" Cyan="100" ID="Ref_6" Magenta="0" Yellow="0"/>
            <Ink ID="Ref_7" Name="Magenta" Type="ProcessMagenta">
              <CMYKColorRef rRef="Ref_8"/>
            </Ink>
            <CMYKColor Black="0" Cyan="0" ID="Ref_8" Magenta="100" Yellow="0"/>
            <Ink ID="Ref_9" Name="Yellow" Type="ProcessYellow">
              <CMYKColorRef rRef="Ref_10"/>
            </Ink>
            <CMYKColor Black="0" Cyan="0" ID="Ref_10" Magenta="0" Yellow="100"/>
            <Ink ID="Ref_11" Name="Black" Type="ProcessBlack">
              <CMYKColorRef rRef="Ref_12"/>
            </Ink>
            <CMYKColor Black="100" Cyan="0" ID="Ref_12" Magenta="0" Yellow="0"/>
            <BindingMachine DeviceID="" ID="Ref_13"/>
            <RGBColor Blue="5" Green="218" ID="Ref_15" Red="98"/>
            <FoldingScheme ID="Ref_17" JDFFoldCatalog="F4-1"/>
            <BindingMachine DeviceID="" ID="Ref_23"/>
            <RGBColor Blue="74" Green="103" ID="Ref_25" Red="110"/>
            <RGBColor Blue="10" Green="90" ID="Ref_31" Red="109"/>
            <RGBColor Blue="239" Green="215" ID="Ref_38" Red="121"/>
            <FoldingScheme ID="Ref_40" JDFFoldCatalog="F12-7"/>
            <RGBColor Blue="211" Green="37" ID="Ref_42" Red="57"/>
            <RGBColor Blue="115" Green="85" ID="Ref_45" Red="59"/>
            <RGBColor Blue="198" Green="63" ID="Ref_55" Red="14"/>
          </ResourcePool>
  <AuditPool>
    <Audit AgentName="APSS" AgentVersion="" Event="Created" TimeStamp="2022-06-06T07:43:55.159432Z"/>
  </AuditPool>
  <Project AutoNumberOut="True" Description="" Name="" Notes="" ProjectID="">
    <ProductPool>
      <Product DueDate="2022-06-07T09:00:00" FinishedTrimHeight="210.0" FinishedTrimWidth="97.5" ID="Ref_0" Name="DE221357184X01" Notes="2500 | ON | 135ma | 4/4 | F-ZBK-8S | BNDLI | SaddleStitch | Links" RequiredQuantity="2500" TextContentFile="" Type="Bound">
        <DisplayColor>
          <RGBColorRef rRef="Ref_1"/>
        </DisplayColor>
        <ComponentPool>
          <Component Active="true" ChildIndex="-1" Cover="false" ID="Ref_2" MIS_ID="DE221357184X01FS01" Priority="1">
            <StockRef rRef="Ref_3"/>
            <FoldingSchemeRef rRef="Ref_4"/>
          </Component>
        </ComponentPool>
        <PagePool>
          <PageDefaults/>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="1" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="2" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="3" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="4" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="5" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="6" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="7" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="8" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
        </PagePool>
        <BindingMachineRef rRef="Ref_13"/>

XSL:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:l="http://www.lithotechnics.com" exclude-result-prefixes="l">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:template match="/">
        <!-- Root -->
        <xsl:element name="Product">
            <xsl:attribute name="ID">
                <xsl:value-of select="//l:Project/@ProjectID"/>
            </xsl:attribute>
            <xsl:attribute name="Version">1.0</xsl:attribute>
            <xsl:attribute name="DueDate"></xsl:attribute>
            <xsl:attribute name="Copies"></xsl:attribute>
            <xsl:attribute name="ProductType">Gang</xsl:attribute>
        </xsl:element>           
                    <xsl:choose>
                    <xsl:variable name="bound" select="l:Resourcepool/l:BindingMachine"/>
                    <xsl:when test="$bound = 1">
                        <xsl:for-each select="//l:Product">
                            <xsl:element name="BoundComponent"/>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="//l:Product">
                            <xsl:element name="UnboundComponent"/>
                        </xsl:for-each>
                    </xsl:otherwise>
                    </xsl:choose>

输出:

    <?xml version="1.0" encoding="utf-8"?>
<Product ID="68174834" Version="1.0" DueDate="" Copies="" ProductType="Gang">
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-12T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-12T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-19T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
</Product>

问题:

因此,我要做的是选择一个选择“ bindingmachine”元素的选择存在,如果是这样,我希望XSL将产品元素命名为“ BoundComponent”,如果不是,则应将其命名为“ UnboundComponent”。 我不确定这是否是最好的方法,或者使用情况下是否更容易,但是无论我到目前为止尝试过什么,我都无法不幸工作,有什么想法吗?

Input XML:

        <?xml version="1.0" encoding="UTF-8"?><MetrixXML xmlns="http://www.lithotechnics.com" DocumentVersion="Metrix" SchemaVersion="1.0" Units="Millimeters">
          <ResourcePool>
            <RGBColor Blue="167" Green="201" ID="Ref_1" Red="108"/>
            <Stock Grade="1" ID="Ref_3" Name="" Thickness="0.25" Vendor="" Weight="135" WeightUnit="gsm"/>
            <FoldingScheme ID="Ref_4" JDFFoldCatalog="F8-7"/>
            <Ink ID="Ref_5" Name="Cyan" Type="ProcessCyan">
              <CMYKColorRef rRef="Ref_6"/>
            </Ink>
            <CMYKColor Black="0" Cyan="100" ID="Ref_6" Magenta="0" Yellow="0"/>
            <Ink ID="Ref_7" Name="Magenta" Type="ProcessMagenta">
              <CMYKColorRef rRef="Ref_8"/>
            </Ink>
            <CMYKColor Black="0" Cyan="0" ID="Ref_8" Magenta="100" Yellow="0"/>
            <Ink ID="Ref_9" Name="Yellow" Type="ProcessYellow">
              <CMYKColorRef rRef="Ref_10"/>
            </Ink>
            <CMYKColor Black="0" Cyan="0" ID="Ref_10" Magenta="0" Yellow="100"/>
            <Ink ID="Ref_11" Name="Black" Type="ProcessBlack">
              <CMYKColorRef rRef="Ref_12"/>
            </Ink>
            <CMYKColor Black="100" Cyan="0" ID="Ref_12" Magenta="0" Yellow="0"/>
            <BindingMachine DeviceID="" ID="Ref_13"/>
            <RGBColor Blue="5" Green="218" ID="Ref_15" Red="98"/>
            <FoldingScheme ID="Ref_17" JDFFoldCatalog="F4-1"/>
            <BindingMachine DeviceID="" ID="Ref_23"/>
            <RGBColor Blue="74" Green="103" ID="Ref_25" Red="110"/>
            <RGBColor Blue="10" Green="90" ID="Ref_31" Red="109"/>
            <RGBColor Blue="239" Green="215" ID="Ref_38" Red="121"/>
            <FoldingScheme ID="Ref_40" JDFFoldCatalog="F12-7"/>
            <RGBColor Blue="211" Green="37" ID="Ref_42" Red="57"/>
            <RGBColor Blue="115" Green="85" ID="Ref_45" Red="59"/>
            <RGBColor Blue="198" Green="63" ID="Ref_55" Red="14"/>
          </ResourcePool>
  <AuditPool>
    <Audit AgentName="APSS" AgentVersion="" Event="Created" TimeStamp="2022-06-06T07:43:55.159432Z"/>
  </AuditPool>
  <Project AutoNumberOut="True" Description="" Name="" Notes="" ProjectID="">
    <ProductPool>
      <Product DueDate="2022-06-07T09:00:00" FinishedTrimHeight="210.0" FinishedTrimWidth="97.5" ID="Ref_0" Name="DE221357184X01" Notes="2500 | ON | 135ma | 4/4 | F-ZBK-8S | BNDLI | SaddleStitch | Links" RequiredQuantity="2500" TextContentFile="" Type="Bound">
        <DisplayColor>
          <RGBColorRef rRef="Ref_1"/>
        </DisplayColor>
        <ComponentPool>
          <Component Active="true" ChildIndex="-1" Cover="false" ID="Ref_2" MIS_ID="DE221357184X01FS01" Priority="1">
            <StockRef rRef="Ref_3"/>
            <FoldingSchemeRef rRef="Ref_4"/>
          </Component>
        </ComponentPool>
        <PagePool>
          <PageDefaults/>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="1" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="2" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="3" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="4" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="5" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="6" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="0.0" BleedRight="2.5" BleedTop="2.5" Number="7" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
          <Page BleedBottom="2.5" BleedLeft="2.5" BleedRight="0.0" BleedTop="2.5" Number="8" Rotation="0">
            <InkRef rRef="Ref_5"/>
            <InkRef rRef="Ref_7"/>
            <InkRef rRef="Ref_9"/>
            <InkRef rRef="Ref_11"/>
          </Page>
        </PagePool>
        <BindingMachineRef rRef="Ref_13"/>

XSL:

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:l="http://www.lithotechnics.com" exclude-result-prefixes="l">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:template match="/">
        <!-- Root -->
        <xsl:element name="Product">
            <xsl:attribute name="ID">
                <xsl:value-of select="//l:Project/@ProjectID"/>
            </xsl:attribute>
            <xsl:attribute name="Version">1.0</xsl:attribute>
            <xsl:attribute name="DueDate"></xsl:attribute>
            <xsl:attribute name="Copies"></xsl:attribute>
            <xsl:attribute name="ProductType">Gang</xsl:attribute>
        </xsl:element>           
                    <xsl:choose>
                    <xsl:variable name="bound" select="l:Resourcepool/l:BindingMachine"/>
                    <xsl:when test="$bound = 1">
                        <xsl:for-each select="//l:Product">
                            <xsl:element name="BoundComponent"/>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="//l:Product">
                            <xsl:element name="UnboundComponent"/>
                        </xsl:for-each>
                    </xsl:otherwise>
                    </xsl:choose>

Output:

    <?xml version="1.0" encoding="utf-8"?>
<Product ID="68174834" Version="1.0" DueDate="" Copies="" ProductType="Gang">
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-12T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-12T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-14T12:00:00" Priority="Normal" Bleed="" Group="" Copies="100" Material="90ma"/>
   <Source src=""/>
   <UnboundComponent ID="" DueDate="2022-04-19T12:00:00" Priority="Normal" Bleed="" Group="" Copies="50" Material="90ma"/>
   <Source src=""/>
</Product>

Question:

So what i'm trying to do is have a choose that checks if the element "BindingMachine" Exists and if so, i want the xsl to name the Product Elements "BoundComponent" if not they should be named "UnboundComponent".
I'm not sure if this is the best way to do it or if it would be easier with an if case, but no matter what i tried so far i couldn't get it to work unfortunatly, any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2025-02-12 12:09:46

我猜你想做类似:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:l="http://www.lithotechnics.com" 
exclude-result-prefixes="l">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/l:MetrixXML">
    <xsl:variable name="elem-name">
        <xsl:choose>
            <xsl:when test="l:ResourcePool/l:BindingMachine">BoundComponent</xsl:when>
            <xsl:otherwise>UnboundComponent</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!-- output -->
    <Product ID="{//l:Project/@ProjectID}" Version="1.0" DueDate="" Copies="" ProductType="Gang">
        <xsl:for-each select="//l:Product">
            <xsl:element name="{$elem-name}">
                <!-- some code here? -->
            </xsl:element>
        </xsl:for-each>
    </Product>
</xsl:template>

</xsl:stylesheet>

I am guessing you want to do something like:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:l="http://www.lithotechnics.com" 
exclude-result-prefixes="l">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/l:MetrixXML">
    <xsl:variable name="elem-name">
        <xsl:choose>
            <xsl:when test="l:ResourcePool/l:BindingMachine">BoundComponent</xsl:when>
            <xsl:otherwise>UnboundComponent</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!-- output -->
    <Product ID="{//l:Project/@ProjectID}" Version="1.0" DueDate="" Copies="" ProductType="Gang">
        <xsl:for-each select="//l:Product">
            <xsl:element name="{$elem-name}">
                <!-- some code here? -->
            </xsl:element>
        </xsl:for-each>
    </Product>
</xsl:template>

</xsl:stylesheet>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文