理解postion()和value-of

本文解析了XSLT中position()函数的作用及应用,通过实例展示了如何获取节点在其选择结果中的位置,而非其在原始XML文档中的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

到底position() 代表了什么呢?它是节点在源文档中的位置吗?

position()是指正在处理的节点在节点集中的位置,而这里的节点集是指使用<xsl:apply-templates>或<xsl:for-each>的select属性所定义的临时结果树(姑且这样理解),所以position()返回的不是节点在源文档中的位置,而是它在临时结果树片段中的位置。

<?xml version="1.0" encoding="UTF-8">

<people>

      <total>3</total>

     <person>

               <name>zhang</name>

               <age>28</age>

     </person>

     <person>

               <name>li</name>

               <age>29</age>

     </person>

     <person>

               <name>wang</name>

               <age>28</age>

     </person>

</people>

XSLT文件:

<xsl:template match="/">

       <xsl:for-each select="people/*">

            <xsl:value-of select="concat(name(),':',postion())"/>

           <xsl:text>    </xsl:text>

       </xsl:for-each>

</xsl:template>

和XSLT文件:

<xsl:template match="/>

      <xsl:for-each select="people/person[age=28]">

              <xsl:value-of select="concat(name(),':',postion())"/>

             <xsl:text>    </xsl:text>

     </xsl:for-each>

</xsl:template>

的输出结果来看

total:1   person:2    person:3   person:4

person:1   person2

也印证了这一点。

另外:<xsl:value-of select="AA"/>和默认模板规则没有什么必然的联系。这一点,我们覆盖默认模板<xsl:template match="text()">即可得出结论。也就是说xsl:value-of 本身即可输出节点的文本内容。

Custom Behaviour ObjectNet provides the facility to create custom behavior and apply it to NetworkObjects ( see Network Behaviour ). To implement your own Behavior you can check the API document on NetworkEntity class. The following piece of code example of how to implement your behavior : public struct DataToSync { public Vector3 positionValue; public Color color; } public class BehaviourExample : NetworkEntity<DataToSync, IDataStream> { private DataToSync currentValue; public BehaviourExample() : base() { } public BehaviourExample(INetworkElement networkObject) : base(networkObject) { } public override void ComputeActive() { this.currentValue.positionValue = this.GetNetworkObject().GetGameObject().transform.position; this.currentValue.color = this.GetNetworkObject().GetGameObject().GetComponent<Renderer>().materials[0].color; } public override void ComputePassive() { this.GetNetworkObject().GetGameObject().transform.position = this.currentValue.positionValue; this.GetNetworkObject().GetGameObject().GetComponent<Renderer>().materials[0].color = this.currentValue.color; } public override DataToSync GetPassiveArguments() { return this.currentValue; } public override void SynchonizePassive(DataToSync data) { this.currentValue.color = data.color; this.currentValue.positionValue = data.positionValue; } public override void SynchonizeActive(IDataStream writer) { writer.Write(this.currentValue.positionValue); writer.Write(this.currentValue.color); } public override void Extract(IDataStream reader) { this.currentValue.positionValue = reader.Read<Vector3>(); this.currentValue.color = reader.Read<Color>(); } } After your behavior is created you need to register it on all objects that you need to synchronize information. public void Awake() { this.GetNetworkElement().RegisterBehavior(new BehaviourExample()); } This code tells ObjectNet to include this behavior during the network synchronization procedure.帮我理解这篇文档
最新发布
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值