XPATH / XSLT:选择父节点的属性与另一个节点的属性匹配的节点
我正在尝试使用 XPath 和 XSLT 对以下 XML 进行转换。
<AuthorGroup>
<Author AffiliationID="A1">
<GivenName>John</GivenName>
<Initials/>
<FamilyName>Smith</FamilyName>
<Degrees/>
<Roles/>
</Author>
<Author AffiliationID="A2">
<GivenName>Bill</GivenName>
<Initials/>
<FamilyName>Atkins</FamilyName>
<Degrees/>
<Roles/>
</Author>
<Affiliation AFFID="A1">
<OrgDivision/>
<OrgName>Some Org</OrgName>
<OrgAddress/>
</Affiliation>
<Affiliation AFFID="A2">
<OrgDivision/>
<OrgName>Another Org</OrgName>
<OrgAddress/>
</Affiliation>
</AuthorGroup>
我正在尝试将作者名称和隶属关系名称合并到一个节点下,因此最终会得到如下结构:
<AUG>
<AU><NAME>John Smith</NAME><AUINFO>Some Org</AUINFO></AU>
<AU><NAME>Bill Atkins</NAME><AUINFO>Another Org</AUINFO></AU>
</AUG>
我正在努力寻找一种选择父节点属性与属性值相匹配的节点的值的方法另一个节点的。例如,对于作者 John Smith,我想选择隶属关系 ID 匹配的节点的值。
到目前为止,我的样式表中有一些代码,如下所示,但我知道节点内的选择不起作用。
<xsl:for-each select="AuthorGroup/Author">
<AU>
<NAME><xsl:value-of select="./FamilyName" /> <xsl:value-of select="./GivenName" /></NAME>
<AUINFO><xsl:value-of select="../Affiliation[@AFFID='NEED TO MATCH AUTHOR AFFILIATIONID']/OrgName" /> </AUINFO>
</AU>
</xsl:for-each>
我应该如何为关联作者选择正确的组织名称值?
非常感谢
吉姆
I'm trying to apply a transformation to the below XML using XPath and XSLT.
<AuthorGroup>
<Author AffiliationID="A1">
<GivenName>John</GivenName>
<Initials/>
<FamilyName>Smith</FamilyName>
<Degrees/>
<Roles/>
</Author>
<Author AffiliationID="A2">
<GivenName>Bill</GivenName>
<Initials/>
<FamilyName>Atkins</FamilyName>
<Degrees/>
<Roles/>
</Author>
<Affiliation AFFID="A1">
<OrgDivision/>
<OrgName>Some Org</OrgName>
<OrgAddress/>
</Affiliation>
<Affiliation AFFID="A2">
<OrgDivision/>
<OrgName>Another Org</OrgName>
<OrgAddress/>
</Affiliation>
</AuthorGroup>
I'm trying to combine the author and affiliation names under one node so I'll end up with a structure like:
<AUG>
<AU><NAME>John Smith</NAME><AUINFO>Some Org</AUINFO></AU>
<AU><NAME>Bill Atkins</NAME><AUINFO>Another Org</AUINFO></AU>
</AUG>
I'm struggling to find a way of selecting the value of a node who's parent node's attribute matches the value of an attribute of an another node. For example, For the author John Smith I'd like to select the value of the node where the affiliation ID's match.
So far I have some code in my stylesheet like the below but I know the selection inside the node is not working.
<xsl:for-each select="AuthorGroup/Author">
<AU>
<NAME><xsl:value-of select="./FamilyName" /> <xsl:value-of select="./GivenName" /></NAME>
<AUINFO><xsl:value-of select="../Affiliation[@AFFID='NEED TO MATCH AUTHOR AFFILIATIONID']/OrgName" /> </AUINFO>
</AU>
</xsl:for-each>
How should I select the value of the correct organisation name for the associated author?
Many thanks
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作为使用变量的替代方法,您可以使用“current()”运算符来获取您所在的当前作者节点
因此,如果您采用以下样式表
并将其应用到给定的 XML,结果应该如下所示
As an alternative to using a variable, you can make use of the "current()" operator to get the current Author node you are on
Thus, if you take the following stylesheet
And apply it your given XML, the results should be like so
键是交叉引用的正确工具。该样式表:
输出:
Keys are the right tool for cross references. This stylesheet:
Output:
只是一个快速回答...希望这有帮助,目前无法自己运行:-S
您可以将 ID 放入变量中,例如:
Just a quick answer ... hope this helps, can't run it myself for the moment :-S
you can put the ID in a variable like: